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. */
10 #include "gras_config.h"
13 #include <pcre.h> /* regular expresion library */
15 #include "surf_private.h"
16 #include "xbt/dynar.h"
18 #include "xbt/config.h"
19 #include "xbt/graph.h"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
25 routing_global_t global_routing = NULL;
26 routing_component_t current_routing = NULL;
27 model_type_t current_routing_model = NULL;
28 static double_f_cpvoid_t get_link_latency = NULL;
30 /* Prototypes of each model */
31 static void *model_full_create(void); /* create structures for full routing model */
32 static void model_full_load(void); /* load parse functions for full routing model */
33 static void model_full_unload(void); /* unload parse functions for full routing model */
34 static void model_full_end(void); /* finalize the creation of full routing model */
35 static void model_full_set_route( /* Set the route and ASroute between src and dst */
36 routing_component_t rc, const char *src, const char *dst, name_route_extended_t route);
38 static void *model_floyd_create(void); /* create structures for floyd routing model */
39 static void model_floyd_load(void); /* load parse functions for floyd routing model */
40 static void model_floyd_unload(void); /* unload parse functions for floyd routing model */
41 static void model_floyd_end(void); /* finalize the creation of floyd routing model */
42 static void model_floyd_set_route(routing_component_t rc, const char *src,
43 const char *dst, name_route_extended_t route);
45 static void *model_dijkstra_both_create(int cached); /* create by calling dijkstra or dijkstracache */
46 static void *model_dijkstra_create(void); /* create structures for dijkstra routing model */
47 static void *model_dijkstracache_create(void); /* create structures for dijkstracache routing model */
48 static void model_dijkstra_both_load(void); /* load parse functions for dijkstra routing model */
49 static void model_dijkstra_both_unload(void); /* unload parse functions for dijkstra routing model */
50 static void model_dijkstra_both_end(void); /* finalize the creation of dijkstra routing model */
51 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
52 const char *dst, name_route_extended_t route);
54 static void *model_rulebased_create(void); /* create structures for rulebased routing model */
55 static void model_rulebased_load(void); /* load parse functions for rulebased routing model */
56 static void model_rulebased_unload(void); /* unload parse functions for rulebased routing model */
57 static void model_rulebased_end(void); /* finalize the creation of rulebased routing model */
59 static void *model_none_create(void); /* none routing model */
60 static void model_none_load(void); /* none routing model */
61 static void model_none_unload(void); /* none routing model */
62 static void model_none_end(void); /* none routing model */
64 static void routing_parse_Scluster(void); /*cluster bypass */
65 static void routing_parse_Speer(void); /*peer bypass */
67 static void routing_parse_Sconfig(void); /*config Tag */
68 static void routing_parse_Econfig(void); /*config Tag */
70 /* this lines are only for replace use like index in the model table */
75 SURF_MODEL_DIJKSTRACACHE,
83 /* must be finish with null and carefull if change de order */
84 struct s_model_type routing_models[] = { {"Full",
85 "Full routing data (fast, large memory requirements, fully expressive)",
91 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
92 model_floyd_create, model_floyd_load, model_floyd_unload,
95 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
96 model_dijkstra_create, model_dijkstra_both_load,
97 model_dijkstra_both_unload, model_dijkstra_both_end},
99 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
100 model_dijkstracache_create, model_dijkstra_both_load,
101 model_dijkstra_both_unload, model_dijkstra_both_end},
102 {"none", "No routing (usable with Constant network only)",
103 model_none_create, model_none_load, model_none_unload, model_none_end},
105 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
106 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
107 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
108 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
110 {NULL, NULL, NULL, NULL, NULL, NULL}
113 /* ************************************************************************** */
114 /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
116 static void generic_set_processing_unit(routing_component_t rc,
118 static void generic_set_autonomous_system(routing_component_t rc,
120 static void generic_set_bypassroute(routing_component_t rc,
121 const char *src, const char *dst,
122 route_extended_t e_route);
124 static int surf_link_resource_cmp(const void *a, const void *b);
125 static int surf_pointer_resource_cmp(const void *a, const void *b);
127 /* ************************************************************************** */
128 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
130 static double generic_get_link_latency(routing_component_t rc, const char *src, const char *dst);
131 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc);
132 static route_extended_t generic_get_bypassroute(routing_component_t rc,
136 /* ************************************************************************** */
137 /* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */
139 static route_extended_t
140 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
141 void *data, int order);
143 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
144 void *data, int order);
145 static void generic_free_route(route_t route);
146 static void generic_free_extended_route(route_extended_t e_route);
147 static routing_component_t
148 generic_autonomous_system_exist(routing_component_t rc, char *element);
149 static routing_component_t
150 generic_processing_units_exist(routing_component_t rc, char *element);
151 static void generic_src_dst_check(routing_component_t rc, const char *src,
154 /* ************************************************************************** */
155 /* **************************** GLOBAL FUNCTIONS **************************** */
157 /* global parse functions */
158 static const char *src = NULL; /* temporary store the source name of a route */
159 static const char *dst = NULL; /* temporary store the destination name of a route */
160 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
161 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
162 static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
164 static xbt_dict_t coordinates = NULL;
167 static double eculidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
169 double src_coord, dst_coord;
171 src_coord = atof(xbt_dynar_get_as(src, index, char *));
172 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
174 return (src_coord-dst_coord)*(src_coord-dst_coord);
178 static double vivaldi_get_link_latency (routing_component_t rc,
179 const char *src, const char *dst)
181 double euclidean_dist;
182 xbt_dynar_t src_ctn, dst_ctn;
183 src_ctn = xbt_dict_get(coordinates, src);
184 dst_ctn = xbt_dict_get(coordinates, dst);
186 euclidean_dist = sqrt (eculidean_dist_comp(0,src_ctn,dst_ctn)+eculidean_dist_comp(1,src_ctn,dst_ctn))
187 +fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
189 xbt_assert2(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
191 return euclidean_dist;
194 x = atof(xbt_dynar_get_as(src_ctn, 0, char *))-atof(xbt_dynar_get_as(dst_ctn, 0, char *));
195 y = atof(xbt_dynar_get_as(src_ctn, 1, char *));
196 h = atof(xbt_dynar_get_as(ctn, 2, char *));
197 sqrt((c1->x - c2->x) * (c1->x - c2->x) + (c1->y - c2->y) * (c1->y - c2->y)) + fabs(c1->h) + fabs(c2->h);
199 if (strcmp(coord,"")) {
200 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
201 xbt_dynar_shrink(ctn,0);
202 xbt_dict_set (coordinates,host_id,ctn,NULL);
208 * \brief Add a "host" to the network element list
210 static void parse_S_host(const char *host_id, const char* coord)
212 network_element_info_t info = NULL;
213 if (current_routing->hierarchy == SURF_ROUTING_NULL)
214 current_routing->hierarchy = SURF_ROUTING_BASE;
215 xbt_assert1(!xbt_dict_get_or_null
216 (global_routing->where_network_elements, host_id),
217 "Reading a host, processing unit \"%s\" already exists",
219 xbt_assert1(current_routing->set_processing_unit,
220 "no defined method \"set_processing_unit\" in \"%s\"",
221 current_routing->name);
222 (*(current_routing->set_processing_unit)) (current_routing, host_id);
223 info = xbt_new0(s_network_element_info_t, 1);
224 info->rc_component = current_routing;
225 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
226 xbt_dict_set(global_routing->where_network_elements, host_id,
227 (void *) info, xbt_free);
229 if (strcmp(coord,"")) {
230 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
231 xbt_dynar_shrink(ctn,0);
232 xbt_dict_set (coordinates,host_id,ctn,NULL);
236 static void parse_E_host(void)
238 xbt_dict_cursor_t cursor = NULL;
242 xbt_dict_foreach(current_property_set, cursor, key, elem) {
243 DEBUG2("property : %s = %s",key,elem);
248 * \brief Add a host to the network element list from XML
250 static void parse_S_host_XML(void)
252 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
254 static void parse_E_host_XML(void)
260 * \brief Add a host to the network element list from lua script
262 static void parse_S_host_lua(const char *host_id, const char *coord)
264 parse_S_host(host_id, coord);
269 * \brief Add a "router" to the network element list
271 static void parse_S_router(void)
273 network_element_info_t info = NULL;
275 if (current_routing->hierarchy == SURF_ROUTING_NULL)
276 current_routing->hierarchy = SURF_ROUTING_BASE;
277 xbt_assert1(!xbt_dict_get_or_null
278 (global_routing->where_network_elements,
279 A_surfxml_router_id),
280 "Reading a router, processing unit \"%s\" already exists",
281 A_surfxml_router_id);
282 xbt_assert1(current_routing->set_processing_unit,
283 "no defined method \"set_processing_unit\" in \"%s\"",
284 current_routing->name);
285 (*(current_routing->set_processing_unit)) (current_routing,
286 A_surfxml_router_id);
287 info = xbt_new0(s_network_element_info_t, 1);
288 info->rc_component = current_routing;
289 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
290 xbt_dict_set(global_routing->where_network_elements, A_surfxml_router_id,
291 (void *) info, xbt_free);
293 TRACE_surf_host_declaration(A_surfxml_router_id, 0);
295 if (strcmp(A_surfxml_router_coordinates,"")) {
296 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
297 xbt_dynar_shrink(ctn,0);
298 xbt_dict_set (coordinates,A_surfxml_router_id,ctn,NULL);
303 * \brief Set the endponints for a route
305 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
307 if (src != NULL && dst != NULL && link_list != NULL)
308 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
312 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0,
313 "Some limits are null in the route between \"%s\" and \"%s\"",
315 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
319 * \brief Set the endpoints for a route from XML
321 static void parse_S_route_new_and_endpoints_XML(void)
323 parse_S_route_new_and_endpoints(A_surfxml_route_src,
324 A_surfxml_route_dst);
328 * \brief Set the endpoints for a route from lua
330 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
332 parse_S_route_new_and_endpoints(id_src, id_dst);
336 * \brief Set the endponints and gateways for a ASroute
338 static void parse_S_ASroute_new_and_endpoints(void)
340 if (src != NULL && dst != NULL && link_list != NULL)
341 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
342 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
343 src = A_surfxml_ASroute_src;
344 dst = A_surfxml_ASroute_dst;
345 gw_src = A_surfxml_ASroute_gw_src;
346 gw_dst = A_surfxml_ASroute_gw_dst;
347 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
348 || strlen(gw_dst) > 0,
349 "Some limits are null in the route between \"%s\" and \"%s\"",
351 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
355 * \brief Set the endponints for a bypassRoute
357 static void parse_S_bypassRoute_new_and_endpoints(void)
359 if (src != NULL && dst != NULL && link_list != NULL)
361 "Bypass Route between %s to %s can not be defined",
362 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
363 src = A_surfxml_bypassRoute_src;
364 dst = A_surfxml_bypassRoute_dst;
365 gw_src = A_surfxml_bypassRoute_gw_src;
366 gw_dst = A_surfxml_bypassRoute_gw_dst;
367 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
368 || strlen(gw_dst) > 0,
369 "Some limits are null in the route between \"%s\" and \"%s\"",
371 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
375 * \brief Set a new link on the actual list of link for a route or ASroute
377 static void parse_E_link_ctn_new_elem(const char *link_id)
380 val = xbt_strdup(link_id);
381 xbt_dynar_push(link_list, &val);
385 * \brief Set a new link on the actual list of link for a route or ASroute from XML
388 static void parse_E_link_ctn_new_elem_XML(void)
390 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
391 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
392 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
393 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
394 parse_E_link_ctn_new_elem(link_id);
397 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
398 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
399 parse_E_link_ctn_new_elem(link_id);
405 * \brief Set a new link on the actual list of link for a route or ASroute from lua
407 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
409 parse_E_link_ctn_new_elem(link_id);
413 * \brief Store the route by calling the set_route function of the current routing component
415 static void parse_E_route_store_route(void)
417 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
418 route->generic_route.link_list = link_list;
419 xbt_assert1(current_routing->set_route,
420 "no defined method \"set_route\" in \"%s\"",
421 current_routing->name);
422 (*(current_routing->set_route)) (current_routing, src, dst, route);
429 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
431 static void parse_E_ASroute_store_route(void)
433 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
434 e_route->generic_route.link_list = link_list;
435 e_route->src_gateway = xbt_strdup(gw_src);
436 e_route->dst_gateway = xbt_strdup(gw_dst);
437 xbt_assert1(current_routing->set_ASroute,
438 "no defined method \"set_ASroute\" in \"%s\"",
439 current_routing->name);
440 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
449 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
451 static void parse_E_bypassRoute_store_route(void)
453 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
454 e_route->generic_route.link_list = link_list;
455 e_route->src_gateway = xbt_strdup(gw_src);
456 e_route->dst_gateway = xbt_strdup(gw_dst);
457 xbt_assert1(current_routing->set_bypassroute,
458 "no defined method \"set_bypassroute\" in \"%s\"",
459 current_routing->name);
460 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
470 * \brief Make a new routing component
472 * make the new structure and
473 * set the parsing functions to allows parsing the part of the routing tree
475 static void parse_S_AS(char *AS_id, char *AS_routing)
477 routing_component_t new_routing;
478 model_type_t model = NULL;
479 char *wanted = AS_routing;
481 /* seach the routing model */
482 for (cpt = 0; routing_models[cpt].name; cpt++)
483 if (!strcmp(wanted, routing_models[cpt].name))
484 model = &routing_models[cpt];
485 /* if its not exist, error */
487 fprintf(stderr, "Routing model %s not found. Existing models:\n",
489 for (cpt = 0; routing_models[cpt].name; cpt++)
490 if (!strcmp(wanted, routing_models[cpt].name))
491 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
492 routing_models[cpt].desc);
496 /* make a new routing component */
497 new_routing = (routing_component_t) (*(model->create)) ();
498 new_routing->routing = model;
499 new_routing->hierarchy = SURF_ROUTING_NULL;
500 new_routing->name = xbt_strdup(AS_id);
501 new_routing->routing_sons = xbt_dict_new();
503 /* Hack for Vivaldi */
504 if(!strcmp(model->name,"Vivaldi"))
505 new_routing->get_latency = vivaldi_get_link_latency;
507 if (current_routing == NULL && global_routing->root == NULL) {
509 /* it is the first one */
510 new_routing->routing_father = NULL;
511 global_routing->root = new_routing;
513 } else if (current_routing != NULL && global_routing->root != NULL) {
515 xbt_assert1(!xbt_dict_get_or_null
516 (current_routing->routing_sons, AS_id),
517 "The AS \"%s\" already exists", AS_id);
518 /* it is a part of the tree */
519 new_routing->routing_father = current_routing;
520 /* set the father behavior */
521 if (current_routing->hierarchy == SURF_ROUTING_NULL)
522 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
523 /* add to the sons dictionary */
524 xbt_dict_set(current_routing->routing_sons, AS_id,
525 (void *) new_routing, NULL);
526 /* add to the father element list */
527 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
528 /* unload the prev parse rules */
529 (*(current_routing->routing->unload)) ();
532 THROW0(arg_error, 0, "All defined components must be belong to a AS");
534 /* set the new parse rules */
535 (*(new_routing->routing->load)) ();
536 /* set the new current component of the tree */
537 current_routing = new_routing;
541 * Detect the routing model type of the routing component from XML platforms
543 static void parse_S_AS_XML(void)
545 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
549 * define the routing model type of routing component from lua script
551 static void parse_S_AS_lua(char *id, char *mode)
553 parse_S_AS(id, mode);
558 * \brief Finish the creation of a new routing component
560 * When you finish to read the routing component, other structures must be created.
561 * the "end" method allow to do that for any routing model type
563 static void parse_E_AS(const char *AS_id)
566 if (current_routing == NULL) {
567 THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id);
569 network_element_info_t info = NULL;
570 xbt_assert1(!xbt_dict_get_or_null
571 (global_routing->where_network_elements,
572 current_routing->name), "The AS \"%s\" already exists",
573 current_routing->name);
574 info = xbt_new0(s_network_element_info_t, 1);
575 info->rc_component = current_routing->routing_father;
576 info->rc_type = SURF_NETWORK_ELEMENT_AS;
577 xbt_dict_set(global_routing->where_network_elements,
578 current_routing->name, info, xbt_free);
579 (*(current_routing->routing->unload)) ();
580 (*(current_routing->routing->end)) ();
581 current_routing = current_routing->routing_father;
582 if (current_routing != NULL)
583 (*(current_routing->routing->load)) ();
588 * \brief Finish the creation of a new routing component from XML
590 static void parse_E_AS_XML(void)
592 parse_E_AS(A_surfxml_AS_id);
596 * \brief Finish the creation of a new routing component from lua
598 static void parse_E_AS_lua(const char *id)
603 /* Aux Business methods */
606 * \brief Get the AS father and the first elements of the chain
608 * \param src the source host name
609 * \param dst the destination host name
611 * Get the common father of the to processing units, and the first different
612 * father in the chain
614 static xbt_dynar_t elements_father(const char *src, const char *dst)
617 xbt_assert0(src && dst, "bad parameters for \"elements_father\" method");
619 xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
621 routing_component_t src_as, dst_as;
622 int index_src, index_dst, index_father_src, index_father_dst;
623 xbt_dynar_t path_src = NULL;
624 xbt_dynar_t path_dst = NULL;
625 routing_component_t current = NULL;
626 routing_component_t *current_src = NULL;
627 routing_component_t *current_dst = NULL;
628 routing_component_t *father = NULL;
630 /* (1) find the as where the src and dst are located */
631 src_as = ((network_element_info_t)
632 xbt_dict_get_or_null(global_routing->where_network_elements,
634 dst_as = ((network_element_info_t)
635 xbt_dict_get_or_null(global_routing->where_network_elements,
639 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
642 /* (2) find the path to the root routing component */
643 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
645 while (current != NULL) {
646 xbt_dynar_push(path_src, ¤t);
647 current = current->routing_father;
649 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
651 while (current != NULL) {
652 xbt_dynar_push(path_dst, ¤t);
653 current = current->routing_father;
656 /* (3) find the common father */
657 index_src = path_src->used - 1;
658 index_dst = path_dst->used - 1;
659 current_src = xbt_dynar_get_ptr(path_src, index_src);
660 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
661 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
662 current_src = xbt_dynar_get_ptr(path_src, index_src);
663 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
669 current_src = xbt_dynar_get_ptr(path_src, index_src);
670 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
672 /* (4) they are not in the same routing component, make the path */
673 index_father_src = index_src + 1;
674 index_father_dst = index_dst + 1;
676 if (*current_src == *current_dst)
677 father = current_src;
679 father = xbt_dynar_get_ptr(path_src, index_father_src);
681 /* (5) result generation */
682 xbt_dynar_push(result, father); /* first same the father of src and dst */
683 xbt_dynar_push(result, current_src); /* second the first different father of src */
684 xbt_dynar_push(result, current_dst); /* three the first different father of dst */
686 xbt_dynar_free(&path_src);
687 xbt_dynar_free(&path_dst);
692 /* Global Business methods */
695 * \brief Recursive function for get_route
697 * \param src the source host name
698 * \param dst the destination host name
700 * This fuction is call by "get_route". It allow to walk through the
701 * routing components tree.
703 static route_extended_t _get_route(const char *src, const char *dst)
707 unsigned int cpt = 0;
709 DEBUG2("Solve route \"%s\" to \"%s\"", src, dst);
711 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
713 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
716 xbt_dynar_t elem_father_list = elements_father(src, dst);
718 routing_component_t common_father =
719 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
720 routing_component_t src_father =
721 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
722 routing_component_t dst_father =
723 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
725 e_route = xbt_new0(s_route_extended_t, 1);
726 e_route->src_gateway = NULL;
727 e_route->dst_gateway = NULL;
728 e_route->generic_route.link_list =
729 xbt_dynar_new(global_routing->size_of_link, NULL);
731 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
733 if (strcmp(src, dst)) {
735 (*(common_father->get_route)) (common_father, src, dst);
736 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
738 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
739 xbt_dynar_push(e_route->generic_route.link_list, &link);
741 generic_free_extended_route(e_route_cnt);
744 } else { /* SURF_ROUTING_RECURSIVE */
746 route_extended_t e_route_bypass = NULL;
748 if (common_father->get_bypass_route)
750 (*(common_father->get_bypass_route)) (common_father, src, dst);
753 e_route_cnt = e_route_bypass;
756 (*(common_father->get_route)) (common_father, src_father->name,
759 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
760 src_father->name, dst_father->name);
762 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
763 (e_route_cnt->dst_gateway == NULL),
764 "bad gateway for route between \"%s\" and \"%s\"", src,
767 if (strcmp(src, e_route_cnt->src_gateway)) {
768 e_route_src = _get_route(src, e_route_cnt->src_gateway);
769 xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
770 e_route_cnt->src_gateway);
771 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
772 xbt_dynar_push(e_route->generic_route.link_list, &link);
776 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
777 xbt_dynar_push(e_route->generic_route.link_list, &link);
780 if (strcmp(e_route_cnt->dst_gateway, dst)) {
781 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
782 xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
783 e_route_cnt->dst_gateway, dst);
784 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
785 xbt_dynar_push(e_route->generic_route.link_list, &link);
789 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
790 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
792 generic_free_extended_route(e_route_src);
793 generic_free_extended_route(e_route_cnt);
794 generic_free_extended_route(e_route_dst);
797 xbt_dynar_free(&elem_father_list);
802 static double _get_latency(const char *src, const char *dst)
804 double latency, latency_src, latency_dst = 0.0;
806 DEBUG2("Solve route \"%s\" to \"%s\"", src, dst);
808 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
810 route_extended_t e_route_cnt;
812 xbt_dynar_t elem_father_list = elements_father(src, dst);
814 routing_component_t common_father =
815 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
816 routing_component_t src_father =
817 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
818 routing_component_t dst_father =
819 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
821 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
823 if (strcmp(src, dst)) {
825 (*(common_father->get_latency)) (common_father, src, dst);
826 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"", src,
829 } else { /* SURF_ROUTING_RECURSIVE */
830 route_extended_t e_route_bypass = NULL;
832 if (common_father->get_bypass_route)
834 (*(common_father->get_bypass_route)) (common_father, src, dst);
836 xbt_assert0(!e_route_bypass,"Bypass cannot work yet with get_latency");
839 (*(common_father->get_route)) (common_father, src_father->name,
842 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
843 src_father->name, dst_father->name);
845 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
846 (e_route_cnt->dst_gateway == NULL),
847 "bad gateway for route between \"%s\" and \"%s\"", src,
850 (*(common_father->get_latency)) (common_father, e_route_cnt->src_gateway,
851 e_route_cnt->src_gateway);
852 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"",
853 src_father->name, dst_father->name);
856 if (src != e_route_cnt->src_gateway) {
858 latency_src = _get_latency(src, e_route_cnt->src_gateway);
859 xbt_assert2(latency_src>=0, "no route between \"%s\" and \"%s\"", src,
860 e_route_cnt->src_gateway);
861 latency += latency_src;
864 if (e_route_cnt->dst_gateway != dst) {
866 latency_dst = _get_latency(e_route_cnt->dst_gateway, dst);
867 xbt_assert2(latency_dst>=0, "no route between \"%s\" and \"%s\"",
868 e_route_cnt->dst_gateway, dst);
869 latency += latency_dst;
874 xbt_dynar_free(&elem_father_list);
880 * \brief Generic method: find a route between hosts
882 * \param src the source host name
883 * \param dst the destination host name
885 * walk through the routing components tree and find a route between hosts
886 * by calling the differents "get_route" functions in each routing component.
887 * No need to free the returned dynar. It will be freed at the next call.
889 static xbt_dynar_t get_route(const char *src, const char *dst)
892 route_extended_t e_route;
893 xbt_dynar_t elem_father_list = NULL;
894 routing_component_t common_father = NULL;
896 if (strcmp(src, dst))
897 e_route = _get_route(src, dst);
899 elem_father_list = elements_father(src, dst);
901 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
903 e_route = (*(common_father->get_route)) (common_father, src, dst);
904 xbt_dynar_free(&elem_father_list);
907 xbt_assert2(e_route, "no route between \"%s\" and \"%s\"", src, dst);
909 if (global_routing->last_route)
910 xbt_dynar_free(&(global_routing->last_route));
911 global_routing->last_route = e_route->generic_route.link_list;
913 if (e_route->src_gateway)
914 xbt_free(e_route->src_gateway);
915 if (e_route->dst_gateway)
916 xbt_free(e_route->dst_gateway);
921 if (xbt_dynar_length(global_routing->last_route) == 0)
925 return global_routing->last_route;
929 * \brief Generic method: find a route between hosts
931 * \param src the source host name
932 * \param dst the destination host name
934 * walk through the routing components tree and find a route between hosts
935 * by calling the differents "get_route" functions in each routing component.
936 * Leaves the caller the responsability to clean the returned dynar.
938 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
940 xbt_dynar_t d = get_route(src,dst);
941 global_routing->last_route = NULL;
946 static double get_latency(const char *src, const char *dst)
949 double latency = -1.0;
950 xbt_dynar_t elem_father_list = elements_father(src, dst);
951 routing_component_t common_father =
952 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
954 if (strcmp(src, dst))
955 latency = _get_latency(src, dst);
957 latency = (*(common_father->get_latency)) (common_father, src, dst);
959 xbt_assert2(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst);
960 xbt_dynar_free(&elem_father_list);
966 * \brief Recursive function for finalize
968 * \param rc the source host name
970 * This fuction is call by "finalize". It allow to finalize the
971 * AS or routing components. It delete all the structures.
973 static void _finalize(routing_component_t rc)
976 xbt_dict_cursor_t cursor = NULL;
978 routing_component_t elem;
979 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
982 xbt_dict_t tmp_sons = rc->routing_sons;
983 char *tmp_name = rc->name;
984 xbt_dict_free(&tmp_sons);
986 xbt_assert1(rc->finalize, "no defined method \"finalize\" in \"%s\"",
987 current_routing->name);
988 (*(rc->finalize)) (rc);
993 * \brief Generic method: delete all the routing structures
995 * walk through the routing components tree and delete the structures
996 * by calling the differents "finalize" functions in each routing component
998 static void finalize(void)
1000 /* delete recursibly all the tree */
1001 _finalize(global_routing->root);
1002 /* delete "where" dict */
1003 xbt_dict_free(&(global_routing->where_network_elements));
1004 xbt_dict_free(&(coordinates));
1005 /* delete last_route */
1006 xbt_dynar_free(&(global_routing->last_route));
1007 /* delete global routing structure */
1008 xbt_free(global_routing);
1011 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
1013 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1015 //adding my one link routes
1018 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
1020 xbt_dynar_foreach(onelink_mine, cpt, link) {
1021 xbt_dynar_push(ret, &link);
1026 xbt_dict_cursor_t cursor = NULL;
1027 routing_component_t rc_child;
1028 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
1029 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
1030 if (onelink_child) {
1031 xbt_dynar_foreach(onelink_child, cpt, link) {
1032 xbt_dynar_push(ret, &link);
1039 static xbt_dynar_t get_onelink_routes(void)
1041 return recursive_get_onelink_routes(global_routing->root);
1044 static e_surf_network_element_type_t get_network_element_type(const char
1047 network_element_info_t rc = NULL;
1048 rc = xbt_dict_get(global_routing->where_network_elements, name);
1053 * \brief Generic method: create the global routing schema
1055 * Make a global routing structure and set all the parsing functions.
1057 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
1060 /* config the uniq global routing */
1061 global_routing = xbt_new0(s_routing_global_t, 1);
1062 global_routing->where_network_elements = xbt_dict_new();
1063 global_routing->root = NULL;
1064 global_routing->get_route = get_route;
1065 global_routing->get_latency = get_latency;
1066 global_routing->get_route_no_cleanup = get_route_no_cleanup;
1067 global_routing->get_onelink_routes = get_onelink_routes;
1068 global_routing->get_network_element_type = get_network_element_type;
1069 global_routing->finalize = finalize;
1070 global_routing->loopback = loopback;
1071 global_routing->size_of_link = size_of_links;
1072 global_routing->last_route = NULL;
1073 get_link_latency = get_link_latency_fun;
1074 /* no current routing at moment */
1075 current_routing = NULL;
1077 coordinates = xbt_dict_new();
1079 /* parse generic elements */
1080 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
1081 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
1082 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
1084 surfxml_add_callback(STag_surfxml_route_cb_list,
1085 &parse_S_route_new_and_endpoints_XML);
1086 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
1087 &parse_S_ASroute_new_and_endpoints);
1088 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
1089 &parse_S_bypassRoute_new_and_endpoints);
1091 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
1092 &parse_E_link_ctn_new_elem_XML);
1094 surfxml_add_callback(ETag_surfxml_route_cb_list,
1095 &parse_E_route_store_route);
1096 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
1097 &parse_E_ASroute_store_route);
1098 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
1099 &parse_E_bypassRoute_store_route);
1101 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
1102 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
1104 surfxml_add_callback(STag_surfxml_cluster_cb_list,
1105 &routing_parse_Scluster);
1107 surfxml_add_callback(STag_surfxml_peer_cb_list,
1108 &routing_parse_Speer);
1110 surfxml_add_callback(STag_surfxml_config_cb_list,
1111 &routing_parse_Sconfig);
1112 surfxml_add_callback(ETag_surfxml_config_cb_list,
1113 &routing_parse_Econfig);
1116 /* ************************************************************************** */
1117 /* *************************** FULL ROUTING ********************************* */
1119 #define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
1121 /* Routing model structure */
1124 s_routing_component_t generic_routing;
1125 route_extended_t *routing_table;
1126 } s_routing_component_full_t, *routing_component_full_t;
1128 /* Business methods */
1129 static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
1131 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1133 routing_component_full_t routing = (routing_component_full_t) rc;
1134 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1135 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1136 char *k1, *d1, *k2, *d2;
1137 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1138 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1139 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k1);
1140 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k2);
1143 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1145 route_extended_t route = TO_ROUTE_FULL(*src_id, *dst_id);
1147 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1149 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1151 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1152 onelink->link_ptr = link;
1153 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1154 onelink->src = xbt_strdup(k1);
1155 onelink->dst = xbt_strdup(k2);
1156 } else if (routing->generic_routing.hierarchy ==
1157 SURF_ROUTING_RECURSIVE) {
1158 onelink->src = xbt_strdup(route->src_gateway);
1159 onelink->dst = xbt_strdup(route->dst_gateway);
1161 xbt_dynar_push(ret, &onelink);
1169 static route_extended_t full_get_route(routing_component_t rc,
1170 const char *src, const char *dst)
1172 xbt_assert1(rc && src
1174 "Invalid params for \"get_route\" function at AS \"%s\"",
1177 /* set utils vars */
1178 routing_component_full_t routing = (routing_component_full_t) rc;
1179 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1181 generic_src_dst_check(rc, src, dst);
1182 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1183 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1186 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1189 route_extended_t e_route = NULL;
1190 route_extended_t new_e_route = NULL;
1192 unsigned int cpt = 0;
1194 e_route = TO_ROUTE_FULL(*src_id, *dst_id);
1197 new_e_route = xbt_new0(s_route_extended_t, 1);
1198 new_e_route->src_gateway = xbt_strdup(e_route->src_gateway);
1199 new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway);
1200 new_e_route->generic_route.link_list =
1201 xbt_dynar_new(global_routing->size_of_link, NULL);
1202 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
1203 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1209 static void full_finalize(routing_component_t rc)
1211 routing_component_full_t routing = (routing_component_full_t) rc;
1212 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1215 /* Delete routing table */
1216 for (i = 0; i < table_size; i++)
1217 for (j = 0; j < table_size; j++)
1218 generic_free_extended_route(TO_ROUTE_FULL(i, j));
1219 xbt_free(routing->routing_table);
1220 /* Delete bypass dict */
1221 xbt_dict_free(&rc->bypassRoutes);
1222 /* Delete index dict */
1223 xbt_dict_free(&rc->to_index);
1224 /* Delete structure */
1229 /* Creation routing model functions */
1231 static void *model_full_create(void)
1233 routing_component_full_t new_component =
1234 xbt_new0(s_routing_component_full_t, 1);
1235 new_component->generic_routing.set_processing_unit =
1236 generic_set_processing_unit;
1237 new_component->generic_routing.set_autonomous_system =
1238 generic_set_autonomous_system;
1239 new_component->generic_routing.set_route = model_full_set_route;
1240 new_component->generic_routing.set_ASroute = model_full_set_route;
1241 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1242 new_component->generic_routing.get_route = full_get_route;
1243 new_component->generic_routing.get_latency = generic_get_link_latency;
1244 new_component->generic_routing.get_onelink_routes =
1245 full_get_onelink_routes;
1246 new_component->generic_routing.get_bypass_route =
1247 generic_get_bypassroute;
1248 new_component->generic_routing.finalize = full_finalize;
1249 new_component->generic_routing.to_index = xbt_dict_new();
1250 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1251 return new_component;
1254 static void model_full_load(void)
1256 /* use "surfxml_add_callback" to add a parse function call */
1259 static void model_full_unload(void)
1261 /* use "surfxml_del_callback" to remove a parse function call */
1264 static void model_full_end(void)
1267 route_extended_t e_route;
1269 /* set utils vars */
1270 routing_component_full_t routing =
1271 ((routing_component_full_t) current_routing);
1272 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1274 /* Create table if necessary */
1275 if(!routing->routing_table)
1276 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1278 /* Add the loopback if needed */
1279 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1280 for (i = 0; i < table_size; i++) {
1281 e_route = TO_ROUTE_FULL(i, i);
1283 e_route = xbt_new0(s_route_extended_t, 1);
1284 e_route->src_gateway = NULL;
1285 e_route->dst_gateway = NULL;
1286 e_route->generic_route.link_list =
1287 xbt_dynar_new(global_routing->size_of_link, NULL);
1288 xbt_dynar_push(e_route->generic_route.link_list,
1289 &global_routing->loopback);
1290 TO_ROUTE_FULL(i, i) = e_route;
1296 static void model_full_set_route(routing_component_t rc, const char *src,
1297 const char *dst, name_route_extended_t route)
1299 int *src_id, *dst_id;
1300 src_id = xbt_dict_get_or_null(rc->to_index, src);
1301 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1302 routing_component_full_t routing = ((routing_component_full_t) rc);
1303 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1306 && dst_id, "Network elements %s or %s not found", src, dst);
1308 xbt_assert2(xbt_dynar_length(route->generic_route.link_list) > 0,
1309 "Invalid count of links, must be greater than zero (%s,%s)",
1312 if(!routing->routing_table)
1313 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1315 if(TO_ROUTE_FULL(*src_id, *dst_id))
1319 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1320 xbt_dynar_foreach(route->generic_route.link_list,i,link_name)
1322 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1323 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1324 xbt_dynar_push(link_route_to_test,&link);
1326 xbt_assert2(!xbt_dynar_compare(
1327 (void*)TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list,
1328 (void*)link_route_to_test,
1329 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1330 "The route between \"%s\" and \"%s\" already exists", src,dst);
1331 xbt_dynar_free(&link_route_to_test);
1335 if(!route->dst_gateway && !route->src_gateway)
1336 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1338 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1339 route->src_gateway, dst, route->dst_gateway);
1340 TO_ROUTE_FULL(*src_id, *dst_id) = generic_new_extended_route(rc->hierarchy,route,1);
1341 xbt_dynar_shrink(TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list, 0);
1344 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1345 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1347 if(route->dst_gateway && route->src_gateway)
1349 char *gw_src = xbt_strdup(route->src_gateway);
1350 char *gw_dst = xbt_strdup(route->dst_gateway);
1351 route->src_gateway = gw_dst;
1352 route->dst_gateway = gw_src;
1354 if(TO_ROUTE_FULL(*dst_id, *src_id))
1358 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1359 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1361 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1362 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1363 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1364 xbt_dynar_push(link_route_to_test,&link);
1366 xbt_assert2(!xbt_dynar_compare(
1367 (void*)TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list,
1368 (void*)link_route_to_test,
1369 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1370 "The route between \"%s\" and \"%s\" already exists", src,dst);
1371 xbt_dynar_free(&link_route_to_test);
1375 if(!route->dst_gateway && !route->src_gateway)
1376 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1378 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1379 route->src_gateway, src, route->dst_gateway);
1380 TO_ROUTE_FULL(*dst_id, *src_id) = generic_new_extended_route(rc->hierarchy,route,0);
1381 xbt_dynar_shrink(TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list, 0);
1387 /* ************************************************************************** */
1388 /* *************************** FLOYD ROUTING ******************************** */
1390 #define TO_FLOYD_COST(i,j) (routing->cost_table)[(i)+(j)*table_size]
1391 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
1392 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
1394 /* Routing model structure */
1397 s_routing_component_t generic_routing;
1398 /* vars for calculate the floyd algorith. */
1399 int *predecessor_table;
1401 route_extended_t *link_table; /* char* -> int* */
1402 } s_routing_component_floyd_t, *routing_component_floyd_t;
1404 static route_extended_t floyd_get_route(routing_component_t rc,
1405 const char *src, const char *dst);
1407 /* Business methods */
1408 static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
1410 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1412 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1413 //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1414 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1415 char *k1, *d1, *k2, *d2;
1416 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1417 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1418 route_extended_t route = floyd_get_route(rc, k1, k2);
1420 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1422 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1424 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1425 onelink->link_ptr = link;
1426 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1427 onelink->src = xbt_strdup(k1);
1428 onelink->dst = xbt_strdup(k2);
1429 } else if (routing->generic_routing.hierarchy ==
1430 SURF_ROUTING_RECURSIVE) {
1431 onelink->src = xbt_strdup(route->src_gateway);
1432 onelink->dst = xbt_strdup(route->dst_gateway);
1434 xbt_dynar_push(ret, &onelink);
1442 static route_extended_t floyd_get_route(routing_component_t rc,
1443 const char *src, const char *dst)
1445 xbt_assert1(rc && src
1447 "Invalid params for \"get_route\" function at AS \"%s\"",
1450 /* set utils vars */
1451 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1452 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1454 generic_src_dst_check(rc, src, dst);
1455 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1456 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1459 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1462 /* create a result route */
1463 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1464 new_e_route->generic_route.link_list =
1465 xbt_dynar_new(global_routing->size_of_link, NULL);
1466 new_e_route->src_gateway = NULL;
1467 new_e_route->dst_gateway = NULL;
1472 char *gw_src = NULL, *gw_dst =
1473 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1480 pred = TO_FLOYD_PRED(*src_id, pred);
1481 if (pred == -1) /* if no pred in route -> no route to host */
1483 xbt_assert2(TO_FLOYD_LINK(pred, prev_pred),
1484 "Invalid link for the route between \"%s\" or \"%s\"", src,
1487 prev_gw_src = gw_src;
1488 prev_gw_dst = gw_dst;
1490 route_extended_t e_route = TO_FLOYD_LINK(pred, prev_pred);
1491 gw_src = e_route->src_gateway;
1492 gw_dst = e_route->dst_gateway;
1497 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && !first
1498 && strcmp(gw_dst, prev_gw_src)) {
1499 xbt_dynar_t e_route_as_to_as =
1500 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1501 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1502 gw_dst, prev_gw_src);
1503 links = e_route_as_to_as;
1505 xbt_dynar_foreach(links, cpt, link) {
1506 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1512 links = e_route->generic_route.link_list;
1513 xbt_dynar_foreach(links, cpt, link) {
1514 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1518 } while (pred != *src_id);
1519 xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")",
1520 *src_id, *dst_id, src, dst);
1522 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1523 new_e_route->src_gateway = xbt_strdup(gw_src);
1524 new_e_route->dst_gateway = xbt_strdup(first_gw);
1530 static void floyd_finalize(routing_component_t rc)
1532 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1536 table_size = xbt_dict_length(routing->generic_routing.to_index);
1537 /* Delete link_table */
1538 for (i = 0; i < table_size; i++)
1539 for (j = 0; j < table_size; j++)
1540 generic_free_extended_route(TO_FLOYD_LINK(i, j));
1541 xbt_free(routing->link_table);
1542 /* Delete bypass dict */
1543 xbt_dict_free(&routing->generic_routing.bypassRoutes);
1544 /* Delete index dict */
1545 xbt_dict_free(&(routing->generic_routing.to_index));
1546 /* Delete dictionary index dict, predecessor and links table */
1547 xbt_free(routing->predecessor_table);
1548 /* Delete structure */
1553 static void *model_floyd_create(void)
1555 routing_component_floyd_t new_component =
1556 xbt_new0(s_routing_component_floyd_t, 1);
1557 new_component->generic_routing.set_processing_unit =
1558 generic_set_processing_unit;
1559 new_component->generic_routing.set_autonomous_system =
1560 generic_set_autonomous_system;
1561 new_component->generic_routing.set_route = model_floyd_set_route;
1562 new_component->generic_routing.set_ASroute = model_floyd_set_route;
1563 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1564 new_component->generic_routing.get_route = floyd_get_route;
1565 new_component->generic_routing.get_latency = generic_get_link_latency;
1566 new_component->generic_routing.get_onelink_routes =
1567 floyd_get_onelink_routes;
1568 new_component->generic_routing.get_bypass_route =
1569 generic_get_bypassroute;
1570 new_component->generic_routing.finalize = floyd_finalize;
1571 new_component->generic_routing.to_index = xbt_dict_new();
1572 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1573 return new_component;
1576 static void model_floyd_load(void)
1578 /* use "surfxml_add_callback" to add a parse function call */
1581 static void model_floyd_unload(void)
1583 /* use "surfxml_del_callback" to remove a parse function call */
1586 static void model_floyd_end(void)
1589 routing_component_floyd_t routing =
1590 ((routing_component_floyd_t) current_routing);
1592 unsigned int i, j, a, b, c;
1594 /* set the size of table routing */
1595 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1597 if(!routing->link_table)
1599 /* Create Cost, Predecessor and Link tables */
1600 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1601 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1602 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1604 /* Initialize costs and predecessors */
1605 for (i = 0; i < table_size; i++)
1606 for (j = 0; j < table_size; j++) {
1607 TO_FLOYD_COST(i, j) = DBL_MAX;
1608 TO_FLOYD_PRED(i, j) = -1;
1609 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1613 /* Add the loopback if needed */
1614 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1615 for (i = 0; i < table_size; i++) {
1616 route_extended_t e_route = TO_FLOYD_LINK(i, i);
1618 e_route = xbt_new0(s_route_extended_t, 1);
1619 e_route->src_gateway = NULL;
1620 e_route->dst_gateway = NULL;
1621 e_route->generic_route.link_list =
1622 xbt_dynar_new(global_routing->size_of_link, NULL);
1623 xbt_dynar_push(e_route->generic_route.link_list,
1624 &global_routing->loopback);
1625 TO_FLOYD_LINK(i, i) = e_route;
1626 TO_FLOYD_PRED(i, i) = i;
1627 TO_FLOYD_COST(i, i) = 1;
1631 /* Calculate path costs */
1632 for (c = 0; c < table_size; c++) {
1633 for (a = 0; a < table_size; a++) {
1634 for (b = 0; b < table_size; b++) {
1635 if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
1636 if (TO_FLOYD_COST(a, b) == DBL_MAX ||
1637 (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
1638 TO_FLOYD_COST(a, b))) {
1639 TO_FLOYD_COST(a, b) =
1640 TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
1641 TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
1649 static void model_floyd_set_route(routing_component_t rc, const char *src,
1650 const char *dst, name_route_extended_t route)
1652 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1654 /* set the size of table routing */
1655 size_t table_size = xbt_dict_length(rc->to_index);
1656 int *src_id, *dst_id;
1659 src_id = xbt_dict_get_or_null(rc->to_index, src);
1660 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1662 if(!routing->link_table)
1664 /* Create Cost, Predecessor and Link tables */
1665 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1666 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1667 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1669 /* Initialize costs and predecessors */
1670 for (i = 0; i < table_size; i++)
1671 for (j = 0; j < table_size; j++) {
1672 TO_FLOYD_COST(i, j) = DBL_MAX;
1673 TO_FLOYD_PRED(i, j) = -1;
1674 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1678 if(TO_FLOYD_LINK(*src_id, *dst_id))
1680 if(!route->dst_gateway && !route->src_gateway)
1681 DEBUG2("See Route from \"%s\" to \"%s\"", src, dst);
1683 DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1684 route->src_gateway, dst, route->dst_gateway);
1687 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1688 xbt_dynar_foreach(route->generic_route.link_list,cpt,link_name)
1690 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1691 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1692 xbt_dynar_push(link_route_to_test,&link);
1694 xbt_assert2(!xbt_dynar_compare(
1695 (void*)TO_FLOYD_LINK(*src_id, *dst_id)->generic_route.link_list,
1696 (void*)link_route_to_test,
1697 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1698 "The route between \"%s\" and \"%s\" already exists", src,dst);
1699 xbt_free(link_route_to_test);
1703 if(!route->dst_gateway && !route->src_gateway)
1704 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1706 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1707 route->src_gateway, dst, route->dst_gateway);
1709 TO_FLOYD_LINK(*src_id, *dst_id) =
1710 generic_new_extended_route(rc->hierarchy, route, 1);
1711 TO_FLOYD_PRED(*src_id, *dst_id) = *src_id;
1712 TO_FLOYD_COST(*src_id, *dst_id) =
1713 ((TO_FLOYD_LINK(*src_id, *dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1716 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1717 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1719 if(TO_FLOYD_LINK(*dst_id, *src_id))
1721 if(!route->dst_gateway && !route->src_gateway)
1722 DEBUG2("See Route from \"%s\" to \"%s\"", dst, src);
1724 DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1725 route->src_gateway, src, route->dst_gateway);
1728 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1729 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1731 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1732 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1733 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1734 xbt_dynar_push(link_route_to_test,&link);
1736 xbt_assert2(!xbt_dynar_compare(
1737 (void*)TO_FLOYD_LINK(*dst_id, *src_id)->generic_route.link_list,
1738 (void*)link_route_to_test,
1739 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1740 "The route between \"%s\" and \"%s\" already exists", src,dst);
1741 xbt_free(link_route_to_test);
1745 if(route->dst_gateway && route->src_gateway)
1747 char *gw_src = xbt_strdup(route->src_gateway);
1748 char *gw_dst = xbt_strdup(route->dst_gateway);
1749 route->src_gateway = gw_dst;
1750 route->dst_gateway = gw_src;
1753 if(!route->dst_gateway && !route->src_gateway)
1754 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1756 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1757 route->src_gateway, src, route->dst_gateway);
1759 TO_FLOYD_LINK(*dst_id, *src_id) =
1760 generic_new_extended_route(rc->hierarchy, route, 0);
1761 TO_FLOYD_PRED(*dst_id, *src_id) = *dst_id;
1762 TO_FLOYD_COST(*dst_id, *src_id) =
1763 ((TO_FLOYD_LINK(*dst_id, *src_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1768 /* ************************************************************************** */
1769 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1772 s_routing_component_t generic_routing;
1773 xbt_graph_t route_graph; /* xbt_graph */
1774 xbt_dict_t graph_node_map; /* map */
1775 xbt_dict_t route_cache; /* use in cache mode */
1777 } s_routing_component_dijkstra_t, *routing_component_dijkstra_t;
1780 typedef struct graph_node_data {
1782 int graph_id; /* used for caching internal graph id's */
1783 } s_graph_node_data_t, *graph_node_data_t;
1785 typedef struct graph_node_map_element {
1787 } s_graph_node_map_element_t, *graph_node_map_element_t;
1789 typedef struct route_cache_element {
1792 } s_route_cache_element_t, *route_cache_element_t;
1794 /* Free functions */
1796 static void route_cache_elem_free(void *e)
1798 route_cache_element_t elm = (route_cache_element_t) e;
1800 xbt_free(elm->pred_arr);
1805 static void graph_node_map_elem_free(void *e)
1807 graph_node_map_element_t elm = (graph_node_map_element_t) e;
1813 static void graph_edge_data_free(void *e)
1815 route_extended_t e_route = (route_extended_t) e;
1817 xbt_dynar_free(&(e_route->generic_route.link_list));
1818 if (e_route->src_gateway)
1819 xbt_free(e_route->src_gateway);
1820 if (e_route->dst_gateway)
1821 xbt_free(e_route->dst_gateway);
1826 /* Utility functions */
1828 static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc,
1829 int id, int graph_id)
1831 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1832 xbt_node_t node = NULL;
1833 graph_node_data_t data = NULL;
1834 graph_node_map_element_t elm = NULL;
1836 data = xbt_new0(struct graph_node_data, 1);
1838 data->graph_id = graph_id;
1839 node = xbt_graph_new_node(routing->route_graph, data);
1841 elm = xbt_new0(struct graph_node_map_element, 1);
1843 xbt_dict_set_ext(routing->graph_node_map, (char *) (&id), sizeof(int),
1844 (xbt_set_elm_t) elm, &graph_node_map_elem_free);
1849 static graph_node_map_element_t
1850 graph_node_map_search(routing_component_dijkstra_t rc, int id)
1852 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1853 graph_node_map_element_t elm = (graph_node_map_element_t)
1854 xbt_dict_get_or_null_ext(routing->graph_node_map,
1862 static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id,
1863 int dst_id, route_extended_t e_route)
1865 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1867 xbt_node_t src = NULL;
1868 xbt_node_t dst = NULL;
1869 graph_node_map_element_t src_elm = (graph_node_map_element_t)
1870 xbt_dict_get_or_null_ext(routing->graph_node_map,
1873 graph_node_map_element_t dst_elm = (graph_node_map_element_t)
1874 xbt_dict_get_or_null_ext(routing->graph_node_map,
1879 src = src_elm->node;
1882 dst = dst_elm->node;
1884 /* add nodes if they don't exist in the graph */
1885 if (src_id == dst_id && src == NULL && dst == NULL) {
1886 src = route_graph_new_node(rc, src_id, -1);
1890 src = route_graph_new_node(rc, src_id, -1);
1893 dst = route_graph_new_node(rc, dst_id, -1);
1897 /* add link as edge to graph */
1898 xbt_graph_new_edge(routing->route_graph, src, dst, e_route);
1901 static void add_loopback_dijkstra(routing_component_dijkstra_t rc)
1903 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1905 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1907 xbt_node_t node = NULL;
1908 unsigned int cursor2;
1909 xbt_dynar_foreach(nodes, cursor2, node) {
1910 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1911 xbt_edge_t edge = NULL;
1912 unsigned int cursor;
1915 xbt_dynar_foreach(out_edges, cursor, edge) {
1916 xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1917 if (other_node == node) {
1924 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
1925 e_route->src_gateway = NULL;
1926 e_route->dst_gateway = NULL;
1927 e_route->generic_route.link_list =
1928 xbt_dynar_new(global_routing->size_of_link, NULL);
1929 xbt_dynar_push(e_route->generic_route.link_list,
1930 &global_routing->loopback);
1931 xbt_graph_new_edge(routing->route_graph, node, node, e_route);
1936 /* Business methods */
1937 static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
1939 xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
1942 static route_extended_t dijkstra_get_route(routing_component_t rc,
1946 xbt_assert1(rc && src
1948 "Invalid params for \"get_route\" function at AS \"%s\"",
1951 /* set utils vars */
1952 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1954 generic_src_dst_check(rc, src, dst);
1955 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1956 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1959 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1962 /* create a result route */
1963 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1964 new_e_route->generic_route.link_list =
1965 xbt_dynar_new(global_routing->size_of_link, NULL);
1966 new_e_route->src_gateway = NULL;
1967 new_e_route->dst_gateway = NULL;
1969 int *pred_arr = NULL;
1970 int src_node_id = 0;
1971 int dst_node_id = 0;
1974 route_extended_t e_route;
1978 xbt_dynar_t links = NULL;
1979 route_cache_element_t elm = NULL;
1980 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1982 /* Use the graph_node id mapping set to quickly find the nodes */
1983 graph_node_map_element_t src_elm =
1984 graph_node_map_search(routing, *src_id);
1985 graph_node_map_element_t dst_elm =
1986 graph_node_map_search(routing, *dst_id);
1987 xbt_assert2(src_elm != NULL
1988 && dst_elm != NULL, "src %d or dst %d does not exist",
1990 src_node_id = ((graph_node_data_t)
1991 xbt_graph_node_get_data(src_elm->node))->graph_id;
1992 dst_node_id = ((graph_node_data_t)
1993 xbt_graph_node_get_data(dst_elm->node))->graph_id;
1995 /* if the src and dst are the same *//* fixed, missing in the previous version */
1996 if (src_node_id == dst_node_id) {
1998 xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
1999 xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
2001 xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v);
2003 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
2006 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
2008 links = e_route->generic_route.link_list;
2009 xbt_dynar_foreach(links, cpt, link) {
2010 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
2016 if (routing->cached) {
2017 /*check if there is a cached predecessor list avail */
2018 elm = (route_cache_element_t)
2019 xbt_dict_get_or_null_ext(routing->route_cache, (char *) (&src_id),
2023 if (elm) { /* cached mode and cache hit */
2024 pred_arr = elm->pred_arr;
2025 } else { /* not cached mode or cache miss */
2026 double *cost_arr = NULL;
2027 xbt_heap_t pqueue = NULL;
2030 int nr_nodes = xbt_dynar_length(nodes);
2031 cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
2032 pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
2033 pqueue = xbt_heap_new(nr_nodes, xbt_free);
2036 cost_arr[src_node_id] = 0.0;
2038 for (i = 0; i < nr_nodes; i++) {
2039 if (i != src_node_id) {
2040 cost_arr[i] = DBL_MAX;
2045 /* initialize priority queue */
2046 nodeid = xbt_new0(int, 1);
2048 xbt_heap_push(pqueue, nodeid, cost_arr[i]);
2052 /* apply dijkstra using the indexes from the graph's node array */
2053 while (xbt_heap_size(pqueue) > 0) {
2054 int *v_id = xbt_heap_pop(pqueue);
2055 xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
2056 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
2057 xbt_edge_t edge = NULL;
2058 unsigned int cursor;
2060 xbt_dynar_foreach(out_edges, cursor, edge) {
2061 xbt_node_t u_node = xbt_graph_edge_get_target(edge);
2062 graph_node_data_t data = xbt_graph_node_get_data(u_node);
2063 int u_id = data->graph_id;
2064 route_extended_t tmp_e_route =
2065 (route_extended_t) xbt_graph_edge_get_data(edge);
2066 int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */
2068 if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
2069 pred_arr[u_id] = *v_id;
2070 cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
2071 nodeid = xbt_new0(int, 1);
2073 xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
2077 /* free item popped from pqueue */
2082 xbt_heap_free(pqueue);
2085 /* compose route path with links */
2086 char *gw_src = NULL, *gw_dst =
2087 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
2089 for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
2090 xbt_node_t node_pred_v =
2091 xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
2092 xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
2094 xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
2096 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
2099 prev_gw_src = gw_src;
2100 prev_gw_dst = gw_dst;
2102 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
2103 gw_src = e_route->src_gateway;
2104 gw_dst = e_route->dst_gateway;
2106 if (v == dst_node_id)
2109 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
2110 && strcmp(gw_dst, prev_gw_src)) {
2111 xbt_dynar_t e_route_as_to_as =
2112 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
2113 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
2114 gw_dst, prev_gw_src);
2115 links = e_route_as_to_as;
2117 xbt_dynar_foreach(links, cpt, link) {
2118 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
2124 links = e_route->generic_route.link_list;
2125 xbt_dynar_foreach(links, cpt, link) {
2126 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
2131 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
2132 new_e_route->src_gateway = xbt_strdup(gw_src);
2133 new_e_route->dst_gateway = xbt_strdup(first_gw);
2136 if (routing->cached && elm == NULL) {
2137 /* add to predecessor list of the current src-host to cache */
2138 elm = xbt_new0(struct route_cache_element, 1);
2139 elm->pred_arr = pred_arr;
2141 xbt_dict_set_ext(routing->route_cache, (char *) (&src_id), sizeof(int),
2142 (xbt_set_elm_t) elm, &route_cache_elem_free);
2145 if (!routing->cached)
2151 static void dijkstra_finalize(routing_component_t rc)
2153 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2156 xbt_graph_free_graph(routing->route_graph, &xbt_free,
2157 &graph_edge_data_free, &xbt_free);
2158 xbt_dict_free(&routing->graph_node_map);
2159 if (routing->cached)
2160 xbt_dict_free(&routing->route_cache);
2161 /* Delete bypass dict */
2162 xbt_dict_free(&routing->generic_routing.bypassRoutes);
2163 /* Delete index dict */
2164 xbt_dict_free(&(routing->generic_routing.to_index));
2165 /* Delete structure */
2170 /* Creation routing model functions */
2172 static void *model_dijkstra_both_create(int cached)
2174 routing_component_dijkstra_t new_component =
2175 xbt_new0(s_routing_component_dijkstra_t, 1);
2176 new_component->generic_routing.set_processing_unit =
2177 generic_set_processing_unit;
2178 new_component->generic_routing.set_autonomous_system =
2179 generic_set_autonomous_system;
2180 new_component->generic_routing.set_route = model_dijkstra_both_set_route;
2181 new_component->generic_routing.set_ASroute = model_dijkstra_both_set_route; //TODO
2182 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
2183 new_component->generic_routing.get_route = dijkstra_get_route;
2184 new_component->generic_routing.get_latency = generic_get_link_latency;
2185 new_component->generic_routing.get_onelink_routes =
2186 dijkstra_get_onelink_routes;
2187 new_component->generic_routing.get_bypass_route =
2188 generic_get_bypassroute;
2189 new_component->generic_routing.finalize = dijkstra_finalize;
2190 new_component->cached = cached;
2191 new_component->generic_routing.to_index = xbt_dict_new();
2192 new_component->generic_routing.bypassRoutes = xbt_dict_new();
2193 return new_component;
2196 static void *model_dijkstra_create(void)
2198 return model_dijkstra_both_create(0);
2201 static void *model_dijkstracache_create(void)
2203 return model_dijkstra_both_create(1);
2206 static void model_dijkstra_both_load(void)
2208 /* use "surfxml_add_callback" to add a parse function call */
2211 static void model_dijkstra_both_unload(void)
2213 /* use "surfxml_del_callback" to remove a parse function call */
2216 static void model_dijkstra_both_end(void)
2218 routing_component_dijkstra_t routing =
2219 (routing_component_dijkstra_t) current_routing;
2221 xbt_node_t node = NULL;
2222 unsigned int cursor2;
2223 xbt_dynar_t nodes = NULL;
2225 /* Create the topology graph */
2226 routing->route_graph = xbt_graph_new_graph(1, NULL);
2227 routing->graph_node_map = xbt_dict_new();
2229 if (routing->cached && !routing->route_cache)
2230 routing->route_cache = xbt_dict_new();
2232 /* Add the loopback if needed */
2233 if (current_routing->hierarchy == SURF_ROUTING_BASE)
2234 add_loopback_dijkstra(routing);
2236 /* initialize graph indexes in nodes after graph has been built */
2237 nodes = xbt_graph_get_nodes(routing->route_graph);
2239 xbt_dynar_foreach(nodes, cursor2, node) {
2240 graph_node_data_t data = xbt_graph_node_get_data(node);
2241 data->graph_id = cursor2;
2245 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
2246 const char *dst, name_route_extended_t route)
2248 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2249 int *src_id, *dst_id;
2250 src_id = xbt_dict_get_or_null(rc->to_index, src);
2251 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
2253 if (routing->cached && !routing->route_cache)
2254 routing->route_cache = xbt_dict_new();
2256 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
2257 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
2258 xbt_die("Route symmetrical not supported on model dijkstra");
2260 if(!route->dst_gateway && !route->src_gateway)
2261 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
2263 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
2264 route->src_gateway, dst, route->dst_gateway);
2266 route_extended_t e_route =
2267 generic_new_extended_route(current_routing->hierarchy, route, 1);
2268 route_new_dijkstra(routing, *src_id, *dst_id, e_route);
2271 #ifdef HAVE_PCRE_LIB
2272 /* ************************************************** */
2273 /* ************** RULE-BASED ROUTING **************** */
2275 /* Routing model structure */
2278 s_routing_component_t generic_routing;
2279 xbt_dict_t dict_processing_units;
2280 xbt_dict_t dict_autonomous_systems;
2281 xbt_dynar_t list_route;
2282 xbt_dynar_t list_ASroute;
2283 } s_routing_component_rulebased_t, *routing_component_rulebased_t;
2285 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
2286 typedef struct s_rule_route_extended s_rule_route_extended_t,
2287 *rule_route_extended_t;
2289 struct s_rule_route {
2290 xbt_dynar_t re_str_link; // dynar of char*
2295 struct s_rule_route_extended {
2296 s_rule_route_t generic_rule_route;
2297 char *re_src_gateway;
2298 char *re_dst_gateway;
2301 static void rule_route_free(void *e)
2303 rule_route_t *elem = (rule_route_t *) (e);
2305 xbt_dynar_free(&(*elem)->re_str_link);
2306 pcre_free((*elem)->re_src);
2307 pcre_free((*elem)->re_dst);
2313 static void rule_route_extended_free(void *e)
2315 rule_route_extended_t *elem = (rule_route_extended_t *) e;
2317 xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link);
2318 pcre_free((*elem)->generic_rule_route.re_src);
2319 pcre_free((*elem)->generic_rule_route.re_dst);
2320 xbt_free((*elem)->re_src_gateway);
2321 xbt_free((*elem)->re_dst_gateway);
2326 /* Parse routing model functions */
2328 static void model_rulebased_set_processing_unit(routing_component_t rc,
2331 routing_component_rulebased_t routing =
2332 (routing_component_rulebased_t) rc;
2333 xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
2336 static void model_rulebased_set_autonomous_system(routing_component_t rc,
2339 routing_component_rulebased_t routing =
2340 (routing_component_rulebased_t) rc;
2341 xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
2345 static void model_rulebased_set_route(routing_component_t rc,
2346 const char *src, const char *dst,
2347 name_route_extended_t route)
2349 routing_component_rulebased_t routing =
2350 (routing_component_rulebased_t) rc;
2351 rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
2354 ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL);
2355 xbt_assert3(ruleroute->re_src,
2356 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2357 erroffset, src, error);
2358 ruleroute->re_dst = pcre_compile(dst, 0, &error, &erroffset, NULL);
2359 xbt_assert3(ruleroute->re_src,
2360 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2361 erroffset, dst, error);
2362 ruleroute->re_str_link = route->generic_route.link_list;
2363 xbt_dynar_push(routing->list_route, &ruleroute);
2367 static void model_rulebased_set_ASroute(routing_component_t rc,
2368 const char *src, const char *dst,
2369 name_route_extended_t route)
2371 routing_component_rulebased_t routing =
2372 (routing_component_rulebased_t) rc;
2373 rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
2376 ruleroute_e->generic_rule_route.re_src =
2377 pcre_compile(src, 0, &error, &erroffset, NULL);
2378 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2379 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2380 erroffset, src, error);
2381 ruleroute_e->generic_rule_route.re_dst =
2382 pcre_compile(dst, 0, &error, &erroffset, NULL);
2383 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2384 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2385 erroffset, dst, error);
2386 ruleroute_e->generic_rule_route.re_str_link =
2387 route->generic_route.link_list;
2388 ruleroute_e->re_src_gateway = route->src_gateway;
2389 ruleroute_e->re_dst_gateway = route->dst_gateway;
2390 xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
2391 // xbt_free(route->src_gateway);
2392 // xbt_free(route->dst_gateway);
2396 static void model_rulebased_set_bypassroute(routing_component_t rc,
2399 route_extended_t e_route)
2401 xbt_die("bypass routing not supported for Route-Based model");
2404 #define BUFFER_SIZE 4096 /* result buffer size */
2405 #define OVECCOUNT 30 /* should be a multiple of 3 */
2407 static char *remplace(char *value, const char **src_list, int src_size,
2408 const char **dst_list, int dst_size)
2411 char result_result[BUFFER_SIZE];
2412 int i_result_buffer;
2413 int value_length = (int) strlen(value);
2417 i_result_buffer = 0;
2419 if (value[i] == '$') {
2423 int number_length = 0;
2424 while ('0' <= value[i + number_length]
2425 && value[i + number_length] <= '9') {
2428 xbt_assert2(number_length != 0,
2429 "bad string parameter, no number indication, at offset: %d (\"%s\")",
2433 number = atoi(value + i);
2434 i = i + number_length;
2435 xbt_assert2(i + 2 < value_length,
2436 "bad string parameter, too few chars, at offset: %d (\"%s\")",
2439 // solve the indication
2440 const char **param_list;
2442 if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') {
2443 param_list = src_list;
2444 param_size = src_size;
2445 } else if (value[i] == 'd' && value[i + 1] == 's'
2446 && value[i + 2] == 't') {
2447 param_list = dst_list;
2448 param_size = dst_size;
2451 "bad string parameter, support only \"src\" and \"dst\", at offset: %d (\"%s\")",
2456 xbt_assert4(param_size >= number,
2457 "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",
2458 i, value, param_size, number);
2460 const char *param = param_list[number];
2461 int size = strlen(param);
2463 for (cp = 0; cp < size; cp++) {
2464 result_result[i_result_buffer] = param[cp];
2466 if (i_result_buffer >= BUFFER_SIZE)
2470 result_result[i_result_buffer] = value[i];
2475 } while (i < value_length && i_result_buffer < BUFFER_SIZE);
2477 xbt_assert2(i_result_buffer < BUFFER_SIZE,
2478 "solving string \"%s\", small buffer size (%d)", value,
2480 result_result[i_result_buffer] = 0;
2481 return xbt_strdup(result_result);
2484 static route_extended_t rulebased_get_route(routing_component_t rc,
2487 static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
2489 xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
2490 routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
2492 xbt_dict_cursor_t c1 = NULL;
2496 char *router = NULL;
2497 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2498 if (strstr (k1, "router")){
2503 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2506 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2507 route_extended_t route = rulebased_get_route (rc, router, k1);
2509 int number_of_links = xbt_dynar_length(route->generic_route.link_list);
2510 if (number_of_links != 3) {
2511 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2515 xbt_dynar_get_cpy (route->generic_route.link_list, 2, &link_ptr);
2516 onelink_t onelink = xbt_new0 (s_onelink_t, 1);
2517 onelink->src = xbt_strdup (k1);
2518 onelink->dst = xbt_strdup (router);
2519 onelink->link_ptr = link_ptr;
2520 xbt_dynar_push (ret, &onelink);
2525 /* Business methods */
2526 static route_extended_t rulebased_get_route(routing_component_t rc,
2530 xbt_assert1(rc && src
2532 "Invalid params for \"get_route\" function at AS \"%s\"",
2535 /* set utils vars */
2536 routing_component_rulebased_t routing =
2537 (routing_component_rulebased_t) rc;
2539 int are_processing_units;
2540 xbt_dynar_t rule_list;
2541 if (xbt_dict_get_or_null(routing->dict_processing_units, src)
2542 && xbt_dict_get_or_null(routing->dict_processing_units, dst)) {
2543 are_processing_units = 1;
2544 rule_list = routing->list_route;
2545 } else if (xbt_dict_get_or_null(routing->dict_autonomous_systems, src)
2546 && xbt_dict_get_or_null(routing->dict_autonomous_systems,
2548 are_processing_units = 0;
2549 rule_list = routing->list_ASroute;
2552 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
2557 int src_length = (int) strlen(src);
2558 int dst_length = (int) strlen(dst);
2560 xbt_dynar_t links_list =
2561 xbt_dynar_new(global_routing->size_of_link, NULL);
2563 rule_route_t ruleroute;
2565 int ovector_src[OVECCOUNT];
2566 int ovector_dst[OVECCOUNT];
2567 const char **list_src = NULL;
2568 const char **list_dst = NULL;
2569 xbt_dynar_foreach(rule_list, cpt, ruleroute) {
2571 pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0,
2572 ovector_src, OVECCOUNT);
2575 pcre_exec(ruleroute->re_dst, NULL, dst, dst_length, 0, 0,
2576 ovector_dst, OVECCOUNT);
2578 xbt_assert1(!pcre_get_substring_list
2579 (src, ovector_src, rc_src, &list_src),
2580 "error solving substring list for src \"%s\"", src);
2581 xbt_assert1(!pcre_get_substring_list
2582 (dst, ovector_dst, rc_dst, &list_dst),
2583 "error solving substring list for src \"%s\"", dst);
2585 xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) {
2586 char *new_link_name =
2587 remplace(link_name, list_src, rc_src, list_dst, rc_dst);
2589 xbt_dict_get_or_null(surf_network_model->resource_set,
2592 xbt_dynar_push(links_list, &link);
2594 THROW1(mismatch_error, 0, "Link %s not found", new_link_name);
2595 xbt_free(new_link_name);
2599 if (rc_src >= 0 && rc_dst >= 0)
2603 route_extended_t new_e_route = NULL;
2604 if (rc_src >= 0 && rc_dst >= 0) {
2605 new_e_route = xbt_new0(s_route_extended_t, 1);
2606 new_e_route->generic_route.link_list = links_list;
2607 } else if (!strcmp(src, dst) && are_processing_units) {
2608 new_e_route = xbt_new0(s_route_extended_t, 1);
2609 xbt_dynar_push(links_list, &(global_routing->loopback));
2610 new_e_route->generic_route.link_list = links_list;
2612 xbt_dynar_free(&link_list);
2615 if (!are_processing_units && new_e_route) {
2616 rule_route_extended_t ruleroute_extended =
2617 (rule_route_extended_t) ruleroute;
2618 new_e_route->src_gateway =
2619 remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
2621 new_e_route->dst_gateway =
2622 remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
2627 pcre_free_substring_list(list_src);
2629 pcre_free_substring_list(list_dst);
2634 static route_extended_t rulebased_get_bypass_route(routing_component_t rc,
2641 static void rulebased_finalize(routing_component_t rc)
2643 routing_component_rulebased_t routing =
2644 (routing_component_rulebased_t) rc;
2646 xbt_dict_free(&routing->dict_processing_units);
2647 xbt_dict_free(&routing->dict_autonomous_systems);
2648 xbt_dynar_free(&routing->list_route);
2649 xbt_dynar_free(&routing->list_ASroute);
2650 /* Delete structure */
2655 /* Creation routing model functions */
2656 static void *model_rulebased_create(void)
2658 routing_component_rulebased_t new_component =
2659 xbt_new0(s_routing_component_rulebased_t, 1);
2660 new_component->generic_routing.set_processing_unit =
2661 model_rulebased_set_processing_unit;
2662 new_component->generic_routing.set_autonomous_system =
2663 model_rulebased_set_autonomous_system;
2664 new_component->generic_routing.set_route = model_rulebased_set_route;
2665 new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
2666 new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
2667 new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
2668 new_component->generic_routing.get_route = rulebased_get_route;
2669 new_component->generic_routing.get_latency = generic_get_link_latency;
2670 new_component->generic_routing.get_bypass_route = rulebased_get_bypass_route;
2671 new_component->generic_routing.finalize = rulebased_finalize;
2672 /* initialization of internal structures */
2673 new_component->dict_processing_units = xbt_dict_new();
2674 new_component->dict_autonomous_systems = xbt_dict_new();
2675 new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
2676 new_component->list_ASroute =
2677 xbt_dynar_new(sizeof(rule_route_extended_t),
2678 &rule_route_extended_free);
2679 return new_component;
2682 static void model_rulebased_load(void)
2684 /* use "surfxml_add_callback" to add a parse function call */
2687 static void model_rulebased_unload(void)
2689 /* use "surfxml_del_callback" to remove a parse function call */
2692 static void model_rulebased_end(void)
2696 #endif /* HAVE_PCRE_LIB */
2698 /* ************************************************************************** */
2699 /* ******************************* NO ROUTING ******************************* */
2701 /* Routing model structure */
2703 s_routing_component_t generic_routing;
2704 } s_routing_component_none_t, *routing_component_none_t;
2706 /* Business methods */
2707 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc)
2712 static route_extended_t none_get_route(routing_component_t rc,
2713 const char *src, const char *dst)
2718 static route_extended_t none_get_bypass_route(routing_component_t rc,
2725 static void none_finalize(routing_component_t rc)
2730 static void none_set_processing_unit(routing_component_t rc,
2735 static void none_set_autonomous_system(routing_component_t rc,
2740 /* Creation routing model functions */
2741 static void *model_none_create(void)
2743 routing_component_none_t new_component =
2744 xbt_new0(s_routing_component_none_t, 1);
2745 new_component->generic_routing.set_processing_unit =
2746 none_set_processing_unit;
2747 new_component->generic_routing.set_autonomous_system =
2748 none_set_autonomous_system;
2749 new_component->generic_routing.set_route = NULL;
2750 new_component->generic_routing.set_ASroute = NULL;
2751 new_component->generic_routing.set_bypassroute = NULL;
2752 new_component->generic_routing.get_route = none_get_route;
2753 new_component->generic_routing.get_onelink_routes =
2754 none_get_onelink_routes;
2755 new_component->generic_routing.get_bypass_route = none_get_bypass_route;
2756 new_component->generic_routing.finalize = none_finalize;
2757 return new_component;
2760 static void model_none_load(void)
2764 static void model_none_unload(void)
2768 static void model_none_end(void)
2772 /* ************************************************** */
2773 /* ********** PATERN FOR NEW ROUTING **************** */
2775 /* The minimal configuration of a new routing model need the next functions,
2776 * also you need to set at the start of the file, the new model in the model
2777 * list. Remember keep the null ending of the list.
2779 /*** Routing model structure ***/
2781 // s_routing_component_t generic_routing;
2782 // /* things that your routing model need */
2783 // } s_routing_component_NEW_t,*routing_component_NEW_t;
2785 /*** Parse routing model functions ***/
2786 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
2787 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
2788 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
2789 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
2790 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
2792 /*** Business methods ***/
2793 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2794 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2795 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
2797 /*** Creation routing model functions ***/
2798 // static void* model_NEW_create(void) {
2799 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
2800 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
2801 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
2802 // new_component->generic_routing.set_route = model_NEW_set_route;
2803 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
2804 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
2805 // new_component->generic_routing.get_route = NEW_get_route;
2806 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
2807 // new_component->generic_routing.finalize = NEW_finalize;
2808 // /* initialization of internal structures */
2809 // return new_component;
2810 // } /* mandatory */
2811 // static void model_NEW_load(void) {} /* mandatory */
2812 // static void model_NEW_unload(void) {} /* mandatory */
2813 // static void model_NEW_end(void) {} /* mandatory */
2815 /* ************************************************************************** */
2816 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
2818 static void generic_set_processing_unit(routing_component_t rc,
2821 DEBUG1("Load process unit \"%s\"", name);
2822 int *id = xbt_new0(int, 1);
2823 xbt_dict_t _to_index;
2824 _to_index = current_routing->to_index;
2825 *id = xbt_dict_length(_to_index);
2826 xbt_dict_set(_to_index, name, id, xbt_free);
2829 static void generic_set_autonomous_system(routing_component_t rc,
2832 DEBUG1("Load Autonomous system \"%s\"", name);
2833 int *id = xbt_new0(int, 1);
2834 xbt_dict_t _to_index;
2835 _to_index = current_routing->to_index;
2836 *id = xbt_dict_length(_to_index);
2837 xbt_dict_set(_to_index, name, id, xbt_free);
2840 static int surf_pointer_resource_cmp(const void *a, const void *b)
2845 static int surf_link_resource_cmp(const void *a, const void *b)
2847 return !!memcmp(a,b,global_routing->size_of_link);
2850 static void generic_set_bypassroute(routing_component_t rc,
2851 const char *src, const char *dst,
2852 route_extended_t e_route)
2854 DEBUG2("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
2855 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2858 route_name = bprintf("%s#%s", src, dst);
2859 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2860 "Invalid count of links, must be greater than zero (%s,%s)",
2862 xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
2863 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
2864 src, e_route->src_gateway, dst, e_route->dst_gateway);
2866 route_extended_t new_e_route =
2867 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
2868 xbt_dynar_free(&(e_route->generic_route.link_list));
2871 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
2872 (void (*)(void *)) generic_free_extended_route);
2873 xbt_free(route_name);
2876 /* ************************************************************************** */
2877 /* *********************** GENERIC BUSINESS METHODS ************************* */
2879 static double generic_get_link_latency(routing_component_t rc,
2880 const char *src, const char *dst)
2882 route_extended_t route = rc->get_route(rc,src,dst);
2885 double latency = 0.0;
2887 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
2888 latency += get_link_latency(link);
2890 generic_free_extended_route(route);
2894 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
2896 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
2899 static route_extended_t generic_get_bypassroute(routing_component_t rc,
2903 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2904 routing_component_t src_as, dst_as;
2905 int index_src, index_dst;
2906 xbt_dynar_t path_src = NULL;
2907 xbt_dynar_t path_dst = NULL;
2908 routing_component_t current = NULL;
2909 routing_component_t *current_src = NULL;
2910 routing_component_t *current_dst = NULL;
2912 /* (1) find the as where the src and dst are located */
2913 src_as = ((network_element_info_t)
2914 xbt_dict_get_or_null(global_routing->where_network_elements,
2915 src))->rc_component;
2916 dst_as = ((network_element_info_t)
2917 xbt_dict_get_or_null(global_routing->where_network_elements,
2918 dst))->rc_component;
2921 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
2924 /* (2) find the path to the root routing component */
2925 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
2927 while (current != NULL) {
2928 xbt_dynar_push(path_src, ¤t);
2929 current = current->routing_father;
2931 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
2933 while (current != NULL) {
2934 xbt_dynar_push(path_dst, ¤t);
2935 current = current->routing_father;
2938 /* (3) find the common father */
2939 index_src = path_src->used - 1;
2940 index_dst = path_dst->used - 1;
2941 current_src = xbt_dynar_get_ptr(path_src, index_src);
2942 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2943 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
2944 routing_component_t *tmp_src, *tmp_dst;
2945 tmp_src = xbt_dynar_pop_ptr(path_src);
2946 tmp_dst = xbt_dynar_pop_ptr(path_dst);
2949 current_src = xbt_dynar_get_ptr(path_src, index_src);
2950 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2953 int max_index_src = path_src->used - 1;
2954 int max_index_dst = path_dst->used - 1;
2956 int max_index = max(max_index_src, max_index_dst);
2959 route_extended_t e_route_bypass = NULL;
2961 for (max = 0; max <= max_index; max++) {
2962 for (i = 0; i < max; i++) {
2963 if (i <= max_index_src && max <= max_index_dst) {
2964 char *route_name = bprintf("%s#%s",
2965 (*(routing_component_t *)
2967 (path_src, i)))->name,
2968 (*(routing_component_t *)
2970 (path_dst, max)))->name);
2972 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2973 xbt_free(route_name);
2977 if (max <= max_index_src && i <= max_index_dst) {
2978 char *route_name = bprintf("%s#%s",
2979 (*(routing_component_t *)
2981 (path_src, max)))->name,
2982 (*(routing_component_t *)
2984 (path_dst, i)))->name);
2986 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2987 xbt_free(route_name);
2996 if (max <= max_index_src && max <= max_index_dst) {
2997 char *route_name = bprintf("%s#%s",
2998 (*(routing_component_t *)
3000 (path_src, max)))->name,
3001 (*(routing_component_t *)
3003 (path_dst, max)))->name);
3004 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
3005 xbt_free(route_name);
3011 xbt_dynar_free(&path_src);
3012 xbt_dynar_free(&path_dst);
3014 route_extended_t new_e_route = NULL;
3016 if (e_route_bypass) {
3018 unsigned int cpt = 0;
3019 new_e_route = xbt_new0(s_route_extended_t, 1);
3020 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
3021 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
3022 new_e_route->generic_route.link_list =
3023 xbt_dynar_new(global_routing->size_of_link, NULL);
3024 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
3025 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
3032 /* ************************************************************************** */
3033 /* ************************* GENERIC AUX FUNCTIONS ************************** */
3036 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
3037 void *data, int order)
3043 xbt_dynar_t links = NULL, links_id = NULL;
3045 new_route = xbt_new0(s_route_t, 1);
3046 new_route->link_list =
3047 xbt_dynar_new(global_routing->size_of_link, NULL);
3049 xbt_assert0(hierarchy == SURF_ROUTING_BASE,
3050 "the hierarchy type is not SURF_ROUTING_BASE");
3052 links = ((route_t) data)->link_list;
3055 links_id = new_route->link_list;
3057 xbt_dynar_foreach(links, cpt, link_name) {
3060 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3063 xbt_dynar_push(links_id, &link);
3065 xbt_dynar_unshift(links_id, &link);
3067 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3073 static route_extended_t
3074 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
3075 void *data, int order)
3079 route_extended_t e_route, new_e_route;
3082 xbt_dynar_t links = NULL, links_id = NULL;
3084 new_e_route = xbt_new0(s_route_extended_t, 1);
3085 new_e_route->generic_route.link_list =
3086 xbt_dynar_new(global_routing->size_of_link, NULL);
3087 new_e_route->src_gateway = NULL;
3088 new_e_route->dst_gateway = NULL;
3090 xbt_assert0(hierarchy == SURF_ROUTING_BASE
3091 || hierarchy == SURF_ROUTING_RECURSIVE,
3092 "the hierarchy type is not defined");
3094 if (hierarchy == SURF_ROUTING_BASE) {
3096 route = (route_t) data;
3097 links = route->link_list;
3099 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
3101 e_route = (route_extended_t) data;
3102 xbt_assert0(e_route->src_gateway
3103 && e_route->dst_gateway, "bad gateway, is null");
3104 links = e_route->generic_route.link_list;
3106 /* remeber not erase the gateway names */
3107 new_e_route->src_gateway = e_route->src_gateway;
3108 new_e_route->dst_gateway = e_route->dst_gateway;
3111 links_id = new_e_route->generic_route.link_list;
3113 xbt_dynar_foreach(links, cpt, link_name) {
3116 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3119 xbt_dynar_push(links_id, &link);
3121 xbt_dynar_unshift(links_id, &link);
3123 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3129 static void generic_free_route(route_t route)
3132 xbt_dynar_free(&(route->link_list));
3137 static void generic_free_extended_route(route_extended_t e_route)
3140 xbt_dynar_free(&(e_route->generic_route.link_list));
3141 if (e_route->src_gateway)
3142 xbt_free(e_route->src_gateway);
3143 if (e_route->dst_gateway)
3144 xbt_free(e_route->dst_gateway);
3149 static routing_component_t generic_as_exist(routing_component_t find_from,
3150 routing_component_t to_find)
3152 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3153 xbt_dict_cursor_t cursor = NULL;
3156 routing_component_t elem;
3157 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
3158 if (to_find == elem || generic_as_exist(elem, to_find)) {
3168 static routing_component_t
3169 generic_autonomous_system_exist(routing_component_t rc, char *element)
3171 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3172 routing_component_t element_as, result, elem;
3173 xbt_dict_cursor_t cursor = NULL;
3175 element_as = ((network_element_info_t)
3176 xbt_dict_get_or_null
3177 (global_routing->where_network_elements,
3178 element))->rc_component;
3179 result = ((routing_component_t) - 1);
3180 if (element_as != rc)
3181 result = generic_as_exist(rc, element_as);
3185 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
3186 found = !strcmp(elem->name, element);
3196 static routing_component_t
3197 generic_processing_units_exist(routing_component_t rc, char *element)
3199 routing_component_t element_as;
3200 element_as = ((network_element_info_t)
3201 xbt_dict_get_or_null
3202 (global_routing->where_network_elements,
3203 element))->rc_component;
3204 if (element_as == rc)
3206 return generic_as_exist(rc, element_as);
3209 static void generic_src_dst_check(routing_component_t rc, const char *src,
3213 routing_component_t src_as = ((network_element_info_t)
3214 xbt_dict_get_or_null
3215 (global_routing->where_network_elements,
3216 src))->rc_component;
3217 routing_component_t dst_as = ((network_element_info_t)
3218 xbt_dict_get_or_null
3219 (global_routing->where_network_elements,
3220 dst))->rc_component;
3222 xbt_assert3(src_as != NULL && dst_as != NULL,
3223 "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
3224 src, dst, rc->name);
3225 xbt_assert4(src_as == dst_as,
3226 "The src(%s in %s) and dst(%s in %s) are in differents AS",
3227 src, src_as->name, dst, dst_as->name);
3228 xbt_assert2(rc == dst_as,
3229 "The routing component of src and dst is not the same as the network elements belong (%s==%s)",
3230 rc->name, dst_as->name);
3233 static void routing_parse_Sconfig(void)
3236 DEBUG0("WARNING tag config not yet implemented.");
3237 DEBUG1("Configuration name = %s",A_surfxml_config_id);
3240 static void routing_parse_Econfig(void)
3243 xbt_dict_cursor_t cursor = NULL;
3246 xbt_dict_foreach(current_property_set, cursor, key, elem) {
3247 DEBUG2("property : %s = %s",key,elem);
3251 static void routing_parse_Scluster(void)
3253 static int AX_ptr = 0;
3255 char *cluster_id = A_surfxml_cluster_id;
3256 char *cluster_prefix = A_surfxml_cluster_prefix;
3257 char *cluster_suffix = A_surfxml_cluster_suffix;
3258 char *cluster_radical = A_surfxml_cluster_radical;
3259 char *cluster_power = A_surfxml_cluster_power;
3260 char *cluster_core = A_surfxml_cluster_core;
3261 char *cluster_bw = A_surfxml_cluster_bw;
3262 char *cluster_lat = A_surfxml_cluster_lat;
3263 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
3264 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
3265 char *cluster_availability_file = A_surfxml_cluster_availability_file;
3266 char *cluster_state_file = A_surfxml_cluster_state_file;
3267 char *host_id, *groups, *link_id = NULL;
3268 char *router_id, *link_router, *link_backbone;
3269 char *host_availability_file = NULL;
3270 char *host_state_file = NULL;
3271 char *availability_file = bprintf("%s",cluster_availability_file);
3272 char *state_file = bprintf("%s",cluster_state_file);
3274 xbt_dict_t patterns = xbt_dict_new();
3275 xbt_dict_set(patterns,"id",cluster_id,NULL);
3276 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
3277 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
3280 #ifdef HAVE_PCRE_LIB
3281 char *route_src_dst;
3285 xbt_dynar_t radical_elements;
3286 xbt_dynar_t radical_ends;
3287 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
3288 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
3290 #ifndef HAVE_PCRE_LIB
3291 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3292 char *route_src, *route_dst;
3296 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3297 static unsigned int surfxml_buffer_stack_stack[1024];
3299 surfxml_buffer_stack_stack[0] = 0;
3301 surfxml_bufferstack_push(1);
3303 SURFXML_BUFFER_SET(AS_id, cluster_id);
3304 #ifdef HAVE_PCRE_LIB
3305 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3306 DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
3308 SURFXML_BUFFER_SET(AS_routing, "Full");
3309 DEBUG1("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
3311 SURFXML_START_TAG(AS);
3313 radical_elements = xbt_str_split(cluster_radical, ",");
3314 xbt_dynar_foreach(radical_elements, iter, groups) {
3315 radical_ends = xbt_str_split(groups, "-");
3316 switch (xbt_dynar_length(radical_ends)) {
3318 surf_parse_get_int(&start,
3319 xbt_dynar_get_as(radical_ends, 0, char *));
3320 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
3321 #ifndef HAVE_PCRE_LIB
3322 xbt_dynar_push_as(tab_elements_num, int, start);
3324 link_id = bprintf("%s_link_%d", cluster_id, start);
3326 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\">", host_id, cluster_power);
3327 A_surfxml_host_state = A_surfxml_host_state_ON;
3328 SURFXML_BUFFER_SET(host_id, host_id);
3329 SURFXML_BUFFER_SET(host_power, cluster_power);
3330 SURFXML_BUFFER_SET(host_core, cluster_core);
3331 SURFXML_BUFFER_SET(host_availability, "1.0");
3332 xbt_dict_set(patterns,"radical",bprintf("%d",start),NULL);
3333 availability_file = bprintf("%s",cluster_availability_file);
3334 state_file = bprintf("%s",cluster_state_file);
3335 DEBUG1("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
3336 DEBUG1("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
3337 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
3338 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
3340 SURFXML_START_TAG(host);
3341 SURFXML_END_TAG(host);
3343 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3344 A_surfxml_link_state = A_surfxml_link_state_ON;
3345 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3346 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3347 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3348 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3349 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3350 SURFXML_BUFFER_SET(link_id, link_id);
3351 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3352 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3353 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3354 SURFXML_BUFFER_SET(link_latency_file, "");
3355 SURFXML_BUFFER_SET(link_state_file, "");
3356 SURFXML_START_TAG(link);
3357 SURFXML_END_TAG(link);
3365 surf_parse_get_int(&start,
3366 xbt_dynar_get_as(radical_ends, 0, char *));
3367 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3368 for (i = start; i <= end; i++) {
3369 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
3370 #ifndef HAVE_PCRE_LIB
3371 xbt_dynar_push_as(tab_elements_num, int, i);
3373 link_id = bprintf("%s_link_%d", cluster_id, i);
3375 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"", host_id, cluster_power);
3376 A_surfxml_host_state = A_surfxml_host_state_ON;
3377 SURFXML_BUFFER_SET(host_id, host_id);
3378 SURFXML_BUFFER_SET(host_power, cluster_power);
3379 SURFXML_BUFFER_SET(host_core, cluster_core);
3380 SURFXML_BUFFER_SET(host_availability, "1.0");
3381 xbt_dict_set(patterns,"radical",bprintf("%d",i),NULL);
3382 availability_file = bprintf("%s",cluster_availability_file);
3383 state_file = bprintf("%s",cluster_state_file);
3384 DEBUG1("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
3385 DEBUG1("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
3386 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
3387 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
3389 SURFXML_START_TAG(host);
3390 SURFXML_END_TAG(host);
3392 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3393 A_surfxml_link_state = A_surfxml_link_state_ON;
3394 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3395 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3396 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3397 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3398 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3399 SURFXML_BUFFER_SET(link_id, link_id);
3400 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3401 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3402 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3403 SURFXML_BUFFER_SET(link_latency_file, "");
3404 SURFXML_BUFFER_SET(link_state_file, "");
3405 SURFXML_START_TAG(link);
3406 SURFXML_END_TAG(link);
3414 DEBUG0("Malformed radical");
3417 xbt_dynar_free(&radical_ends);
3419 xbt_dynar_free(&radical_elements);
3423 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
3425 link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
3426 link_backbone = bprintf("%s_backbone", cluster_id);
3428 DEBUG1("<router id=\"%s\"/>", router_id);
3429 SURFXML_BUFFER_SET(router_id, router_id);;
3430 SURFXML_START_TAG(router);
3431 SURFXML_END_TAG(router);
3433 DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,cluster_bw, cluster_lat);
3434 A_surfxml_link_state = A_surfxml_link_state_ON;
3435 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3436 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3437 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3438 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3439 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3440 SURFXML_BUFFER_SET(link_id, link_router);
3441 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3442 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3443 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3444 SURFXML_BUFFER_SET(link_latency_file, "");
3445 SURFXML_BUFFER_SET(link_state_file, "");
3446 SURFXML_START_TAG(link);
3447 SURFXML_END_TAG(link);
3449 DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bw, cluster_lat);
3450 A_surfxml_link_state = A_surfxml_link_state_ON;
3451 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3452 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
3453 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3454 SURFXML_BUFFER_SET(link_id, link_backbone);
3455 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
3456 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
3457 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3458 SURFXML_BUFFER_SET(link_latency_file, "");
3459 SURFXML_BUFFER_SET(link_state_file, "");
3460 SURFXML_START_TAG(link);
3461 SURFXML_END_TAG(link);
3465 #ifdef HAVE_PCRE_LIB
3466 char *new_suffix = xbt_strdup("");
3468 radical_elements = xbt_str_split(cluster_suffix, ".");
3469 xbt_dynar_foreach(radical_elements, iter, groups) {
3470 if (strcmp(groups, "")) {
3471 char *old_suffix = new_suffix;
3472 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
3476 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
3477 xbt_dynar_free(&radical_elements);
3480 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
3481 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
3482 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
3484 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
3485 DEBUG0("symmetrical=\"NO\">");
3486 SURFXML_BUFFER_SET(route_src, route_src_dst);
3487 SURFXML_BUFFER_SET(route_dst, route_src_dst);
3488 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3489 SURFXML_START_TAG(route);
3491 DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_src);
3492 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
3493 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3494 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3495 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3496 SURFXML_START_TAG(link_ctn);
3497 SURFXML_END_TAG(link_ctn);
3499 DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
3500 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
3501 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3502 SURFXML_START_TAG(link_ctn);
3503 SURFXML_END_TAG(link_ctn);
3505 DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
3506 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
3507 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3508 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3509 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3510 SURFXML_START_TAG(link_ctn);
3511 SURFXML_END_TAG(link_ctn);
3514 SURFXML_END_TAG(route);
3516 free(pcre_link_dst);
3517 free(pcre_link_backbone);
3518 free(pcre_link_src);
3519 free(route_src_dst);
3521 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
3522 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
3523 if (i == xbt_dynar_length(tab_elements_num)) {
3524 route_src = router_id;
3527 bprintf("%s%d%s", cluster_prefix,
3528 xbt_dynar_get_as(tab_elements_num, i, int),
3532 if (j == xbt_dynar_length(tab_elements_num)) {
3533 route_dst = router_id;
3536 bprintf("%s%d%s", cluster_prefix,
3537 xbt_dynar_get_as(tab_elements_num, j, int),
3541 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
3542 DEBUG0("symmetrical=\"NO\">");
3543 SURFXML_BUFFER_SET(route_src, route_src);
3544 SURFXML_BUFFER_SET(route_dst, route_dst);
3545 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3546 SURFXML_START_TAG(route);
3548 if (i == xbt_dynar_length(tab_elements_num)) {
3549 route_src = link_router;
3552 bprintf("%s_link_%d", cluster_id,
3553 xbt_dynar_get_as(tab_elements_num, i, int));
3556 if (j == xbt_dynar_length(tab_elements_num)) {
3557 route_dst = link_router;
3560 bprintf("%s_link_%d", cluster_id,
3561 xbt_dynar_get_as(tab_elements_num, j, int));
3564 DEBUG1("<link_ctn\tid=\"%s\"/>", route_src);
3565 SURFXML_BUFFER_SET(link_ctn_id, route_src);
3566 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3567 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3568 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3569 SURFXML_START_TAG(link_ctn);
3570 SURFXML_END_TAG(link_ctn);
3572 DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3573 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3574 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3575 SURFXML_START_TAG(link_ctn);
3576 SURFXML_END_TAG(link_ctn);
3578 DEBUG1("<link_ctn\tid=\"%s\"/>", route_dst);
3579 SURFXML_BUFFER_SET(link_ctn_id, route_dst);
3580 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3581 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3582 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3583 SURFXML_START_TAG(link_ctn);
3584 SURFXML_END_TAG(link_ctn);
3587 SURFXML_END_TAG(route);
3590 xbt_dynar_free(&tab_elements_num);
3595 free(link_backbone);
3597 xbt_dict_free(&patterns);
3598 free(availability_file);
3602 SURFXML_END_TAG(AS);
3605 surfxml_bufferstack_pop(1);
3608 static void routing_parse_Speer(void)
3610 static int AX_ptr = 0;
3612 char *peer_id = A_surfxml_peer_id;
3613 char *peer_power = A_surfxml_peer_power;
3614 char *peer_bw_in = A_surfxml_peer_bw_in;
3615 char *peer_bw_out = A_surfxml_peer_bw_out;
3616 char *peer_lat = A_surfxml_peer_lat;
3617 char *peer_coord = A_surfxml_peer_coordinates;
3618 char *peer_state_file = A_surfxml_peer_state_file;
3619 char *peer_availability_file = A_surfxml_peer_availability_file;
3621 char *host_id = NULL;
3622 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
3624 #ifdef HAVE_PCRE_LIB
3628 int peer_sharing_policy = AX_surfxml_peer_sharing_policy;
3630 #ifndef HAVE_PCRE_LIB
3631 //xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3632 //char *route_src, *route_dst;
3636 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3637 static unsigned int surfxml_buffer_stack_stack[1024];
3639 surfxml_buffer_stack_stack[0] = 0;
3641 surfxml_bufferstack_push(1);
3643 SURFXML_BUFFER_SET(AS_id, peer_id);
3644 #ifdef HAVE_PCRE_LIB
3645 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3646 DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">", peer_id);
3648 SURFXML_BUFFER_SET(AS_routing, "Full");
3649 DEBUG1("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
3651 SURFXML_START_TAG(AS);
3654 host_id = bprintf("peer_%s", peer_id);
3655 router_id = bprintf("router_%s", peer_id);
3656 link_id_up = bprintf("link_%s_up", peer_id);
3657 link_id_down = bprintf("link_%s_down", peer_id);
3659 link_router = bprintf("%s_link_router", peer_id);
3660 link_backbone = bprintf("%s_backbone", peer_id);
3662 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
3663 A_surfxml_host_state = A_surfxml_host_state_ON;
3664 SURFXML_BUFFER_SET(host_id, host_id);
3665 SURFXML_BUFFER_SET(host_power, peer_power);
3666 SURFXML_BUFFER_SET(host_availability, "1.0");
3667 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
3668 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
3669 SURFXML_START_TAG(host);
3670 SURFXML_END_TAG(host);
3672 DEBUG2("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
3673 SURFXML_BUFFER_SET(router_id, router_id);
3674 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
3675 SURFXML_START_TAG(router);
3676 SURFXML_END_TAG(router);
3678 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
3679 A_surfxml_link_state = A_surfxml_link_state_ON;
3680 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3681 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3682 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3683 SURFXML_BUFFER_SET(link_id, link_id_up);
3684 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
3685 SURFXML_BUFFER_SET(link_latency, peer_lat);
3686 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3687 SURFXML_BUFFER_SET(link_latency_file, "");
3688 SURFXML_BUFFER_SET(link_state_file, "");
3689 SURFXML_START_TAG(link);
3690 SURFXML_END_TAG(link);
3692 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
3693 A_surfxml_link_state = A_surfxml_link_state_ON;
3694 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3695 if(peer_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3696 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3697 SURFXML_BUFFER_SET(link_id, link_id_down);
3698 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
3699 SURFXML_BUFFER_SET(link_latency, peer_lat);
3700 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3701 SURFXML_BUFFER_SET(link_latency_file, "");
3702 SURFXML_BUFFER_SET(link_state_file, "");
3703 SURFXML_START_TAG(link);
3704 SURFXML_END_TAG(link);
3709 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", peer_id, router_id);
3710 DEBUG0("symmetrical=\"NO\">");
3711 SURFXML_BUFFER_SET(route_src, peer_id);
3712 SURFXML_BUFFER_SET(route_dst, router_id);
3713 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3714 SURFXML_START_TAG(route);
3716 DEBUG1("<link_ctn\tid=\"%s\"/>", link_id_up);
3717 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
3718 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3719 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3720 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3721 SURFXML_START_TAG(link_ctn);
3722 SURFXML_END_TAG(link_ctn);
3725 SURFXML_END_TAG(route);
3728 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, peer_id);
3729 DEBUG0("symmetrical=\"NO\">");
3730 SURFXML_BUFFER_SET(route_src, router_id);
3731 SURFXML_BUFFER_SET(route_dst, peer_id);
3732 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3733 SURFXML_START_TAG(route);
3735 DEBUG1("<link_ctn\tid=\"%s\"/>", link_id_down);
3736 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
3737 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3738 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3739 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3740 SURFXML_START_TAG(link_ctn);
3741 SURFXML_END_TAG(link_ctn);
3744 SURFXML_END_TAG(route);
3747 SURFXML_END_TAG(AS);
3750 //xbt_dynar_free(&tab_elements_num);
3752 surfxml_bufferstack_pop(1);
3757 * New methods to init the routing model component from the lua script
3761 * calling parse_S_AS_lua with lua values
3763 void routing_AS_init(const char *AS_id, const char *AS_routing)
3765 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
3769 * calling parse_E_AS_lua to fisnish the creation of routing component
3771 void routing_AS_end(const char *AS_id)
3773 parse_E_AS_lua((char *) AS_id);
3777 * add a host to the network element list
3780 void routing_add_host(const char *host_id)
3782 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
3786 * Set a new link on the actual list of link for a route or ASroute
3788 void routing_add_link(const char *link_id)
3790 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
3794 *Set the endpoints for a route
3796 void routing_set_route(const char *src_id, const char *dst_id)
3798 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
3802 * Store the route by calling parse_E_route_store_route
3804 void routing_store_route(void)
3806 parse_E_route_store_route();