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 */
66 static void routing_parse_Sconfig(void); /*config Tag */
67 static void routing_parse_Econfig(void); /*config Tag */
69 /* this lines are only for replace use like index in the model table */
74 SURF_MODEL_DIJKSTRACACHE,
82 /* must be finish with null and carefull if change de order */
83 struct s_model_type routing_models[] = { {"Full",
84 "Full routing data (fast, large memory requirements, fully expressive)",
90 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
91 model_floyd_create, model_floyd_load, model_floyd_unload,
94 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
95 model_dijkstra_create, model_dijkstra_both_load,
96 model_dijkstra_both_unload, model_dijkstra_both_end},
98 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
99 model_dijkstracache_create, model_dijkstra_both_load,
100 model_dijkstra_both_unload, model_dijkstra_both_end},
101 {"none", "No routing (usable with Constant network only)",
102 model_none_create, model_none_load, model_none_unload, model_none_end},
104 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
105 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
107 {NULL, NULL, NULL, NULL, NULL, NULL}
110 /* ************************************************************************** */
111 /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
113 static void generic_set_processing_unit(routing_component_t rc,
115 static void generic_set_autonomous_system(routing_component_t rc,
117 static void generic_set_bypassroute(routing_component_t rc,
118 const char *src, const char *dst,
119 route_extended_t e_route);
121 static int surf_link_resource_cmp(const void *a, const void *b);
122 static int surf_pointer_resource_cmp(const void *a, const void *b);
124 /* ************************************************************************** */
125 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
127 static double generic_get_link_latency(routing_component_t rc, const char *src, const char *dst);
128 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc);
129 static route_extended_t generic_get_bypassroute(routing_component_t rc,
133 /* ************************************************************************** */
134 /* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */
136 static route_extended_t
137 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
138 void *data, int order);
140 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
141 void *data, int order);
142 static void generic_free_route(route_t route);
143 static void generic_free_extended_route(route_extended_t e_route);
144 static routing_component_t
145 generic_autonomous_system_exist(routing_component_t rc, char *element);
146 static routing_component_t
147 generic_processing_units_exist(routing_component_t rc, char *element);
148 static void generic_src_dst_check(routing_component_t rc, const char *src,
151 /* ************************************************************************** */
152 /* **************************** GLOBAL FUNCTIONS **************************** */
154 /* global parse functions */
155 static const char *src = NULL; /* temporary store the source name of a route */
156 static const char *dst = NULL; /* temporary store the destination name of a route */
157 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
158 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
159 static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
161 static xbt_dict_t coordinates = NULL;
164 * \brief Add a "host" to the network element list
166 static void parse_S_host(char *host_id, char* coord)
168 network_element_info_t info = NULL;
169 if (current_routing->hierarchy == SURF_ROUTING_NULL)
170 current_routing->hierarchy = SURF_ROUTING_BASE;
171 xbt_assert1(!xbt_dict_get_or_null
172 (global_routing->where_network_elements, host_id),
173 "Reading a host, processing unit \"%s\" already exists",
175 xbt_assert1(current_routing->set_processing_unit,
176 "no defined method \"set_processing_unit\" in \"%s\"",
177 current_routing->name);
178 (*(current_routing->set_processing_unit)) (current_routing, host_id);
179 info = xbt_new0(s_network_element_info_t, 1);
180 info->rc_component = current_routing;
181 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
182 xbt_dict_set(global_routing->where_network_elements, host_id,
183 (void *) info, NULL);
185 if (strcmp(coord,"")) {
186 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
187 xbt_dynar_shrink(ctn,0);
188 xbt_dict_set (coordinates,host_id,ctn,NULL);
193 * \brief Add a host to the network element list from XML
195 static void parse_S_host_XML(void)
197 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
201 * \brief Add a host to the network element list from lua script
203 static void parse_S_host_lua(char *host_id, char *coord)
205 parse_S_host(host_id, coord);
210 * \brief Add a "router" to the network element list
212 static void parse_S_router(void)
214 network_element_info_t info = NULL;
216 if (current_routing->hierarchy == SURF_ROUTING_NULL)
217 current_routing->hierarchy = SURF_ROUTING_BASE;
218 xbt_assert1(!xbt_dict_get_or_null
219 (global_routing->where_network_elements,
220 A_surfxml_router_id),
221 "Reading a router, processing unit \"%s\" already exists",
222 A_surfxml_router_id);
223 xbt_assert1(current_routing->set_processing_unit,
224 "no defined method \"set_processing_unit\" in \"%s\"",
225 current_routing->name);
226 (*(current_routing->set_processing_unit)) (current_routing,
227 A_surfxml_router_id);
228 info = xbt_new0(s_network_element_info_t, 1);
229 info->rc_component = current_routing;
230 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
231 xbt_dict_set(global_routing->where_network_elements, A_surfxml_router_id,
232 (void *) info, NULL);
234 TRACE_surf_host_declaration(A_surfxml_router_id, 0);
239 * \brief Set the endponints for a route
241 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
243 if (src != NULL && dst != NULL && link_list != NULL)
244 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
248 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0,
249 "Some limits are null in the route between \"%s\" and \"%s\"",
251 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
255 * \brief Set the endpoints for a route from XML
257 static void parse_S_route_new_and_endpoints_XML(void)
259 parse_S_route_new_and_endpoints(A_surfxml_route_src,
260 A_surfxml_route_dst);
264 * \brief Set the endpoints for a route from lua
266 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
268 parse_S_route_new_and_endpoints(id_src, id_dst);
272 * \brief Set the endponints and gateways for a ASroute
274 static void parse_S_ASroute_new_and_endpoints(void)
276 if (src != NULL && dst != NULL && link_list != NULL)
277 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
278 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
279 src = A_surfxml_ASroute_src;
280 dst = A_surfxml_ASroute_dst;
281 gw_src = A_surfxml_ASroute_gw_src;
282 gw_dst = A_surfxml_ASroute_gw_dst;
283 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
284 || strlen(gw_dst) > 0,
285 "Some limits are null in the route between \"%s\" and \"%s\"",
287 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
291 * \brief Set the endponints for a bypassRoute
293 static void parse_S_bypassRoute_new_and_endpoints(void)
295 if (src != NULL && dst != NULL && link_list != NULL)
297 "Bypass Route between %s to %s can not be defined",
298 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
299 src = A_surfxml_bypassRoute_src;
300 dst = A_surfxml_bypassRoute_dst;
301 gw_src = A_surfxml_bypassRoute_gw_src;
302 gw_dst = A_surfxml_bypassRoute_gw_dst;
303 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
304 || strlen(gw_dst) > 0,
305 "Some limits are null in the route between \"%s\" and \"%s\"",
307 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
311 * \brief Set a new link on the actual list of link for a route or ASroute
313 static void parse_E_link_ctn_new_elem(char *link_id)
316 val = xbt_strdup(link_id);
317 xbt_dynar_push(link_list, &val);
321 * \brief Set a new link on the actual list of link for a route or ASroute from XML
324 static void parse_E_link_ctn_new_elem_XML(void)
326 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
327 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
328 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
329 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
330 parse_E_link_ctn_new_elem(link_id);
333 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
334 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
335 parse_E_link_ctn_new_elem(link_id);
341 * \brief Set a new link on the actual list of link for a route or ASroute from lua
343 static void parse_E_link_c_ctn_new_elem_lua(char *link_id)
345 parse_E_link_ctn_new_elem(link_id);
349 * \brief Store the route by calling the set_route function of the current routing component
351 static void parse_E_route_store_route(void)
353 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
354 route->generic_route.link_list = link_list;
355 xbt_assert1(current_routing->set_route,
356 "no defined method \"set_route\" in \"%s\"",
357 current_routing->name);
358 (*(current_routing->set_route)) (current_routing, src, dst, route);
365 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
367 static void parse_E_ASroute_store_route(void)
369 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
370 e_route->generic_route.link_list = link_list;
371 e_route->src_gateway = xbt_strdup(gw_src);
372 e_route->dst_gateway = xbt_strdup(gw_dst);
373 xbt_assert1(current_routing->set_ASroute,
374 "no defined method \"set_ASroute\" in \"%s\"",
375 current_routing->name);
376 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
385 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
387 static void parse_E_bypassRoute_store_route(void)
389 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
390 e_route->generic_route.link_list = link_list;
391 e_route->src_gateway = xbt_strdup(gw_src);
392 e_route->dst_gateway = xbt_strdup(gw_dst);
393 xbt_assert1(current_routing->set_bypassroute,
394 "no defined method \"set_bypassroute\" in \"%s\"",
395 current_routing->name);
396 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
406 * \brief Make a new routing component
408 * make the new structure and
409 * set the parsing functions to allows parsing the part of the routing tree
411 static void parse_S_AS(char *AS_id, char *AS_routing)
413 routing_component_t new_routing;
414 model_type_t model = NULL;
415 char *wanted = AS_routing;
417 /* seach the routing model */
418 for (cpt = 0; routing_models[cpt].name; cpt++)
419 if (!strcmp(wanted, routing_models[cpt].name))
420 model = &routing_models[cpt];
421 /* if its not exist, error */
423 fprintf(stderr, "Routing model %s not found. Existing models:\n",
425 for (cpt = 0; routing_models[cpt].name; cpt++)
426 if (!strcmp(wanted, routing_models[cpt].name))
427 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
428 routing_models[cpt].desc);
432 /* make a new routing component */
433 new_routing = (routing_component_t) (*(model->create)) ();
434 new_routing->routing = model;
435 new_routing->hierarchy = SURF_ROUTING_NULL;
436 new_routing->name = xbt_strdup(AS_id);
437 new_routing->routing_sons = xbt_dict_new();
439 if (current_routing == NULL && global_routing->root == NULL) {
441 /* it is the first one */
442 new_routing->routing_father = NULL;
443 global_routing->root = new_routing;
445 } else if (current_routing != NULL && global_routing->root != NULL) {
447 xbt_assert1(!xbt_dict_get_or_null
448 (current_routing->routing_sons, AS_id),
449 "The AS \"%s\" already exists", AS_id);
450 /* it is a part of the tree */
451 new_routing->routing_father = current_routing;
452 /* set the father behavior */
453 if (current_routing->hierarchy == SURF_ROUTING_NULL)
454 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
455 /* add to the sons dictionary */
456 xbt_dict_set(current_routing->routing_sons, AS_id,
457 (void *) new_routing, NULL);
458 /* add to the father element list */
459 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
460 /* unload the prev parse rules */
461 (*(current_routing->routing->unload)) ();
464 THROW0(arg_error, 0, "All defined components must be belong to a AS");
466 /* set the new parse rules */
467 (*(new_routing->routing->load)) ();
468 /* set the new current component of the tree */
469 current_routing = new_routing;
473 * Detect the routing model type of the routing component from XML platforms
475 static void parse_S_AS_XML(void)
477 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
481 * define the routing model type of routing component from lua script
483 static void parse_S_AS_lua(char *id, char *mode)
485 parse_S_AS(id, mode);
490 * \brief Finish the creation of a new routing component
492 * When you finish to read the routing component, other structures must be created.
493 * the "end" method allow to do that for any routing model type
495 static void parse_E_AS(char *AS_id)
498 if (current_routing == NULL) {
499 THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id);
501 network_element_info_t info = NULL;
502 xbt_assert1(!xbt_dict_get_or_null
503 (global_routing->where_network_elements,
504 current_routing->name), "The AS \"%s\" already exists",
505 current_routing->name);
506 info = xbt_new0(s_network_element_info_t, 1);
507 info->rc_component = current_routing->routing_father;
508 info->rc_type = SURF_NETWORK_ELEMENT_AS;
509 xbt_dict_set(global_routing->where_network_elements,
510 current_routing->name, info, NULL);
511 (*(current_routing->routing->unload)) ();
512 (*(current_routing->routing->end)) ();
513 current_routing = current_routing->routing_father;
514 if (current_routing != NULL)
515 (*(current_routing->routing->load)) ();
520 * \brief Finish the creation of a new routing component from XML
522 static void parse_E_AS_XML(void)
524 parse_E_AS(A_surfxml_AS_id);
528 * \brief Finish the creation of a new routing component from lua
530 static void parse_E_AS_lua(char *id)
535 /* Aux Business methods */
538 * \brief Get the AS father and the first elements of the chain
540 * \param src the source host name
541 * \param dst the destination host name
543 * Get the common father of the to processing units, and the first different
544 * father in the chain
546 static xbt_dynar_t elements_father(const char *src, const char *dst)
549 xbt_assert0(src && dst, "bad parameters for \"elements_father\" method");
551 xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
553 routing_component_t src_as, dst_as;
554 int index_src, index_dst, index_father_src, index_father_dst;
555 xbt_dynar_t path_src = NULL;
556 xbt_dynar_t path_dst = NULL;
557 routing_component_t current = NULL;
558 routing_component_t *current_src = NULL;
559 routing_component_t *current_dst = NULL;
560 routing_component_t *father = NULL;
562 /* (1) find the as where the src and dst are located */
563 src_as = ((network_element_info_t)
564 xbt_dict_get_or_null(global_routing->where_network_elements,
566 dst_as = ((network_element_info_t)
567 xbt_dict_get_or_null(global_routing->where_network_elements,
571 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
574 /* (2) find the path to the root routing component */
575 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
577 while (current != NULL) {
578 xbt_dynar_push(path_src, ¤t);
579 current = current->routing_father;
581 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
583 while (current != NULL) {
584 xbt_dynar_push(path_dst, ¤t);
585 current = current->routing_father;
588 /* (3) find the common father */
589 index_src = path_src->used - 1;
590 index_dst = path_dst->used - 1;
591 current_src = xbt_dynar_get_ptr(path_src, index_src);
592 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
593 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
594 current_src = xbt_dynar_get_ptr(path_src, index_src);
595 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
601 current_src = xbt_dynar_get_ptr(path_src, index_src);
602 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
604 /* (4) they are not in the same routing component, make the path */
605 index_father_src = index_src + 1;
606 index_father_dst = index_dst + 1;
608 if (*current_src == *current_dst)
609 father = current_src;
611 father = xbt_dynar_get_ptr(path_src, index_father_src);
613 /* (5) result generation */
614 xbt_dynar_push(result, father); /* first same the father of src and dst */
615 xbt_dynar_push(result, current_src); /* second the first different father of src */
616 xbt_dynar_push(result, current_dst); /* three the first different father of dst */
618 xbt_dynar_free(&path_src);
619 xbt_dynar_free(&path_dst);
624 /* Global Business methods */
627 * \brief Recursive function for get_route
629 * \param src the source host name
630 * \param dst the destination host name
632 * This fuction is call by "get_route". It allow to walk through the
633 * routing components tree.
635 static route_extended_t _get_route(const char *src, const char *dst)
639 unsigned int cpt = 0;
641 DEBUG2("Solve route \"%s\" to \"%s\"", src, dst);
643 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
645 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
648 xbt_dynar_t elem_father_list = elements_father(src, dst);
650 routing_component_t common_father =
651 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
652 routing_component_t src_father =
653 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
654 routing_component_t dst_father =
655 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
657 e_route = xbt_new0(s_route_extended_t, 1);
658 e_route->src_gateway = NULL;
659 e_route->dst_gateway = NULL;
660 e_route->generic_route.link_list =
661 xbt_dynar_new(global_routing->size_of_link, NULL);
663 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
665 if (strcmp(src, dst)) {
667 (*(common_father->get_route)) (common_father, src, dst);
668 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
670 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
671 xbt_dynar_push(e_route->generic_route.link_list, &link);
673 generic_free_extended_route(e_route_cnt);
676 } else { /* SURF_ROUTING_RECURSIVE */
678 route_extended_t e_route_bypass = NULL;
680 if (common_father->get_bypass_route)
682 (*(common_father->get_bypass_route)) (common_father, src, dst);
685 e_route_cnt = e_route_bypass;
688 (*(common_father->get_route)) (common_father, src_father->name,
691 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
692 src_father->name, dst_father->name);
694 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
695 (e_route_cnt->dst_gateway == NULL),
696 "bad gateway for route between \"%s\" and \"%s\"", src,
699 if (src != e_route_cnt->src_gateway) {
700 e_route_src = _get_route(src, e_route_cnt->src_gateway);
701 xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
702 e_route_cnt->src_gateway);
703 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
704 xbt_dynar_push(e_route->generic_route.link_list, &link);
708 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
709 xbt_dynar_push(e_route->generic_route.link_list, &link);
712 if (e_route_cnt->dst_gateway != dst) {
713 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
714 xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
715 e_route_cnt->dst_gateway, dst);
716 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
717 xbt_dynar_push(e_route->generic_route.link_list, &link);
721 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
722 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
724 generic_free_extended_route(e_route_src);
725 generic_free_extended_route(e_route_cnt);
726 generic_free_extended_route(e_route_dst);
729 xbt_dynar_free(&elem_father_list);
734 static double _get_latency(const char *src, const char *dst)
737 double latency, latency_src, latency_dst = 0.0;
739 DEBUG2("Solve route \"%s\" to \"%s\"", src, dst);
741 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
743 route_extended_t e_route, e_route_cnt;
745 xbt_dynar_t elem_father_list = elements_father(src, dst);
747 routing_component_t common_father =
748 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
749 routing_component_t src_father =
750 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
751 routing_component_t dst_father =
752 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
754 e_route = xbt_new0(s_route_extended_t, 1);
755 e_route->src_gateway = NULL;
756 e_route->dst_gateway = NULL;
757 e_route->generic_route.link_list =
758 xbt_dynar_new(global_routing->size_of_link, NULL);
760 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
762 if (strcmp(src, dst)) {
764 (*(common_father->get_latency)) (common_father, src, dst);
765 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"", src,
768 } else { /* SURF_ROUTING_RECURSIVE */
769 route_extended_t e_route_bypass = NULL;
771 if (common_father->get_bypass_route)
773 (*(common_father->get_bypass_route)) (common_father, src, dst);
775 xbt_assert0(!e_route_bypass,"Bypass cannot work yet with get_latency");
778 (*(common_father->get_route)) (common_father, src_father->name,
781 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
782 src_father->name, dst_father->name);
784 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
785 (e_route_cnt->dst_gateway == NULL),
786 "bad gateway for route between \"%s\" and \"%s\"", src,
789 (*(common_father->get_latency)) (common_father, src_father->name,
791 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"",
792 src_father->name, dst_father->name);
795 if (src != e_route_cnt->src_gateway) {
797 e_route_src = _get_route(src, e_route_cnt->src_gateway);
798 xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
799 e_route_cnt->src_gateway);
800 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
801 xbt_dynar_push(e_route->generic_route.link_list, &link);
804 latency_src = _get_latency(src, e_route_cnt->src_gateway);
805 xbt_assert2(latency_src>=0, "no route between \"%s\" and \"%s\"", src,
806 e_route_cnt->src_gateway);
807 latency += latency_src;
811 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
812 xbt_dynar_push(e_route->generic_route.link_list, &link);
816 if (e_route_cnt->dst_gateway != dst) {
818 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
819 xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
820 e_route_cnt->dst_gateway, dst);
821 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
822 xbt_dynar_push(e_route->generic_route.link_list, &link);
825 latency_dst = _get_latency(e_route_cnt->dst_gateway, dst);
826 xbt_assert2(latency_dst>=0, "no route between \"%s\" and \"%s\"",
827 e_route_cnt->dst_gateway, dst);
828 latency += latency_dst;
832 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
833 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
835 generic_free_extended_route(e_route_src);
836 generic_free_extended_route(e_route_cnt);
837 generic_free_extended_route(e_route_dst);
841 xbt_dynar_free(&elem_father_list);
847 * \brief Generic method: find a route between hosts
849 * \param src the source host name
850 * \param dst the destination host name
852 * walk through the routing components tree and find a route between hosts
853 * by calling the differents "get_route" functions in each routing component.
854 * No need to free the returned dynar. It will be freed at the next call.
856 static xbt_dynar_t get_route(const char *src, const char *dst)
859 route_extended_t e_route;
860 xbt_dynar_t elem_father_list = elements_father(src, dst);
861 routing_component_t common_father =
862 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
864 if (strcmp(src, dst))
865 e_route = _get_route(src, dst);
867 e_route = (*(common_father->get_route)) (common_father, src, dst);
869 xbt_assert2(e_route, "no route between \"%s\" and \"%s\"", src, dst);
871 if (global_routing->last_route)
872 xbt_dynar_free(&(global_routing->last_route));
873 global_routing->last_route = e_route->generic_route.link_list;
875 if (e_route->src_gateway)
876 xbt_free(e_route->src_gateway);
877 if (e_route->dst_gateway)
878 xbt_free(e_route->dst_gateway);
881 xbt_dynar_free(&elem_father_list);
883 if (xbt_dynar_length(global_routing->last_route) == 0)
886 return global_routing->last_route;
890 * \brief Generic method: find a route between hosts
892 * \param src the source host name
893 * \param dst the destination host name
895 * walk through the routing components tree and find a route between hosts
896 * by calling the differents "get_route" functions in each routing component.
897 * Leaves the caller the responsability to clean the returned dynar.
899 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
901 xbt_dynar_t d = get_route(src,dst);
902 global_routing->last_route = NULL;
907 static double get_latency(const char *src, const char *dst)
910 double latency = -1.0;
911 xbt_dynar_t elem_father_list = elements_father(src, dst);
912 routing_component_t common_father =
913 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
915 if (strcmp(src, dst))
916 latency = _get_latency(src, dst);
918 latency = (*(common_father->get_latency)) (common_father, src, dst);
920 xbt_assert2(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst);
926 * \brief Recursive function for finalize
928 * \param rc the source host name
930 * This fuction is call by "finalize". It allow to finalize the
931 * AS or routing components. It delete all the structures.
933 static void _finalize(routing_component_t rc)
936 xbt_dict_cursor_t cursor = NULL;
938 routing_component_t elem;
939 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
942 xbt_dict_t tmp_sons = rc->routing_sons;
943 char *tmp_name = rc->name;
944 xbt_dict_free(&tmp_sons);
946 xbt_assert1(rc->finalize, "no defined method \"finalize\" in \"%s\"",
947 current_routing->name);
948 (*(rc->finalize)) (rc);
953 * \brief Generic method: delete all the routing structures
955 * walk through the routing components tree and delete the structures
956 * by calling the differents "finalize" functions in each routing component
958 static void finalize(void)
960 /* delete recursibly all the tree */
961 _finalize(global_routing->root);
962 /* delete "where" dict */
963 xbt_dict_free(&(global_routing->where_network_elements));
964 xbt_dict_free(&(coordinates));
965 /* delete last_route */
966 xbt_dynar_free(&(global_routing->last_route));
967 /* delete global routing structure */
968 xbt_free(global_routing);
971 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
973 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
975 //adding my one link routes
978 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
980 xbt_dynar_foreach(onelink_mine, cpt, link) {
981 xbt_dynar_push(ret, &link);
986 xbt_dict_cursor_t cursor = NULL;
987 routing_component_t rc_child;
988 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
989 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
991 xbt_dynar_foreach(onelink_child, cpt, link) {
992 xbt_dynar_push(ret, &link);
999 static xbt_dynar_t get_onelink_routes(void)
1001 return recursive_get_onelink_routes(global_routing->root);
1004 static e_surf_network_element_type_t get_network_element_type(const char
1007 network_element_info_t rc = NULL;
1008 rc = xbt_dict_get(global_routing->where_network_elements, name);
1013 * \brief Generic method: create the global routing schema
1015 * Make a global routing structure and set all the parsing functions.
1017 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
1020 /* config the uniq global routing */
1021 global_routing = xbt_new0(s_routing_global_t, 1);
1022 global_routing->where_network_elements = xbt_dict_new();
1023 global_routing->root = NULL;
1024 global_routing->get_route = get_route;
1025 global_routing->get_latency = get_latency;
1026 global_routing->get_route_no_cleanup = get_route_no_cleanup;
1027 global_routing->get_onelink_routes = get_onelink_routes;
1028 global_routing->get_network_element_type = get_network_element_type;
1029 global_routing->finalize = finalize;
1030 global_routing->loopback = loopback;
1031 global_routing->size_of_link = size_of_links;
1032 global_routing->last_route = NULL;
1033 get_link_latency = get_link_latency_fun;
1034 /* no current routing at moment */
1035 current_routing = NULL;
1037 coordinates = xbt_dict_new();
1039 /* parse generic elements */
1040 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
1041 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
1043 surfxml_add_callback(STag_surfxml_route_cb_list,
1044 &parse_S_route_new_and_endpoints_XML);
1045 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
1046 &parse_S_ASroute_new_and_endpoints);
1047 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
1048 &parse_S_bypassRoute_new_and_endpoints);
1050 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
1051 &parse_E_link_ctn_new_elem_XML);
1053 surfxml_add_callback(ETag_surfxml_route_cb_list,
1054 &parse_E_route_store_route);
1055 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
1056 &parse_E_ASroute_store_route);
1057 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
1058 &parse_E_bypassRoute_store_route);
1060 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
1061 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
1063 surfxml_add_callback(STag_surfxml_cluster_cb_list,
1064 &routing_parse_Scluster);
1066 surfxml_add_callback(STag_surfxml_config_cb_list,
1067 &routing_parse_Sconfig);
1068 surfxml_add_callback(ETag_surfxml_config_cb_list,
1069 &routing_parse_Econfig);
1072 /* ************************************************************************** */
1073 /* *************************** FULL ROUTING ********************************* */
1075 #define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
1077 /* Routing model structure */
1080 s_routing_component_t generic_routing;
1081 route_extended_t *routing_table;
1082 } s_routing_component_full_t, *routing_component_full_t;
1084 /* Business methods */
1085 static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
1087 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1089 routing_component_full_t routing = (routing_component_full_t) rc;
1090 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1091 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1092 char *k1, *d1, *k2, *d2;
1093 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1094 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1095 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k1);
1096 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k2);
1099 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1101 route_extended_t route = TO_ROUTE_FULL(*src_id, *dst_id);
1103 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1105 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1107 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1108 onelink->link_ptr = link;
1109 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1110 onelink->src = xbt_strdup(k1);
1111 onelink->dst = xbt_strdup(k2);
1112 } else if (routing->generic_routing.hierarchy ==
1113 SURF_ROUTING_RECURSIVE) {
1114 onelink->src = xbt_strdup(route->src_gateway);
1115 onelink->dst = xbt_strdup(route->dst_gateway);
1117 xbt_dynar_push(ret, &onelink);
1125 static route_extended_t full_get_route(routing_component_t rc,
1126 const char *src, const char *dst)
1128 xbt_assert1(rc && src
1130 "Invalid params for \"get_route\" function at AS \"%s\"",
1133 /* set utils vars */
1134 routing_component_full_t routing = (routing_component_full_t) rc;
1135 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1137 generic_src_dst_check(rc, src, dst);
1138 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1139 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1142 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1145 route_extended_t e_route = NULL;
1146 route_extended_t new_e_route = NULL;
1148 unsigned int cpt = 0;
1150 e_route = TO_ROUTE_FULL(*src_id, *dst_id);
1153 new_e_route = xbt_new0(s_route_extended_t, 1);
1154 new_e_route->src_gateway = xbt_strdup(e_route->src_gateway);
1155 new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway);
1156 new_e_route->generic_route.link_list =
1157 xbt_dynar_new(global_routing->size_of_link, NULL);
1158 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
1159 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1165 static void full_finalize(routing_component_t rc)
1167 routing_component_full_t routing = (routing_component_full_t) rc;
1168 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1171 /* Delete routing table */
1172 for (i = 0; i < table_size; i++)
1173 for (j = 0; j < table_size; j++)
1174 generic_free_extended_route(TO_ROUTE_FULL(i, j));
1175 xbt_free(routing->routing_table);
1176 /* Delete bypass dict */
1177 xbt_dict_free(&rc->bypassRoutes);
1178 /* Delete index dict */
1179 xbt_dict_free(&rc->to_index);
1180 /* Delete structure */
1185 /* Creation routing model functions */
1187 static void *model_full_create(void)
1189 routing_component_full_t new_component =
1190 xbt_new0(s_routing_component_full_t, 1);
1191 new_component->generic_routing.set_processing_unit =
1192 generic_set_processing_unit;
1193 new_component->generic_routing.set_autonomous_system =
1194 generic_set_autonomous_system;
1195 new_component->generic_routing.set_route = model_full_set_route;
1196 new_component->generic_routing.set_ASroute = model_full_set_route;
1197 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1198 new_component->generic_routing.get_route = full_get_route;
1199 new_component->generic_routing.get_latency = generic_get_link_latency;
1200 new_component->generic_routing.get_onelink_routes =
1201 full_get_onelink_routes;
1202 new_component->generic_routing.get_bypass_route =
1203 generic_get_bypassroute;
1204 new_component->generic_routing.finalize = full_finalize;
1205 new_component->generic_routing.to_index = xbt_dict_new();
1206 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1207 return new_component;
1210 static void model_full_load(void)
1212 /* use "surfxml_add_callback" to add a parse function call */
1215 static void model_full_unload(void)
1217 /* use "surfxml_del_callback" to remove a parse function call */
1220 static void model_full_end(void)
1223 route_extended_t e_route;
1225 /* set utils vars */
1226 routing_component_full_t routing =
1227 ((routing_component_full_t) current_routing);
1228 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1230 /* Create table if necessary */
1231 if(!routing->routing_table)
1232 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1234 /* Add the loopback if needed */
1235 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1236 for (i = 0; i < table_size; i++) {
1237 e_route = TO_ROUTE_FULL(i, i);
1239 e_route = xbt_new0(s_route_extended_t, 1);
1240 e_route->src_gateway = NULL;
1241 e_route->dst_gateway = NULL;
1242 e_route->generic_route.link_list =
1243 xbt_dynar_new(global_routing->size_of_link, NULL);
1244 xbt_dynar_push(e_route->generic_route.link_list,
1245 &global_routing->loopback);
1246 TO_ROUTE_FULL(i, i) = e_route;
1252 static void model_full_set_route(routing_component_t rc, const char *src,
1253 const char *dst, name_route_extended_t route)
1255 int *src_id, *dst_id;
1256 src_id = xbt_dict_get_or_null(rc->to_index, src);
1257 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1258 routing_component_full_t routing = ((routing_component_full_t) rc);
1259 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1262 && dst_id, "Network elements %s or %s not found", src, dst);
1264 xbt_assert2(xbt_dynar_length(route->generic_route.link_list) > 0,
1265 "Invalid count of links, must be greater than zero (%s,%s)",
1268 if(!routing->routing_table)
1269 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1271 if(TO_ROUTE_FULL(*src_id, *dst_id))
1275 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1276 xbt_dynar_foreach(route->generic_route.link_list,i,link_name)
1278 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1279 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1280 xbt_dynar_push(link_route_to_test,&link);
1282 xbt_assert2(!xbt_dynar_compare(
1283 (void*)TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list,
1284 (void*)link_route_to_test,
1285 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1286 "The route between \"%s\" and \"%s\" already exists", src,dst);
1287 xbt_free(link_route_to_test);
1291 if(!route->dst_gateway && !route->src_gateway)
1292 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1294 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1295 route->src_gateway, dst, route->dst_gateway);
1296 TO_ROUTE_FULL(*src_id, *dst_id) = generic_new_extended_route(rc->hierarchy,route,1);
1297 xbt_dynar_shrink(TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list, 0);
1300 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1301 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1303 if(route->dst_gateway && route->src_gateway)
1305 char *gw_src = xbt_strdup(route->src_gateway);
1306 char *gw_dst = xbt_strdup(route->dst_gateway);
1307 route->src_gateway = gw_dst;
1308 route->dst_gateway = gw_src;
1310 if(TO_ROUTE_FULL(*dst_id, *src_id))
1314 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1315 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1317 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1318 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1319 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1320 xbt_dynar_push(link_route_to_test,&link);
1322 xbt_assert2(!xbt_dynar_compare(
1323 (void*)TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list,
1324 (void*)link_route_to_test,
1325 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1326 "The route between \"%s\" and \"%s\" already exists", src,dst);
1327 xbt_free(link_route_to_test);
1331 if(!route->dst_gateway && !route->src_gateway)
1332 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1334 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1335 route->src_gateway, src, route->dst_gateway);
1336 TO_ROUTE_FULL(*dst_id, *src_id) = generic_new_extended_route(rc->hierarchy,route,0);
1337 xbt_dynar_shrink(TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list, 0);
1343 /* ************************************************************************** */
1344 /* *************************** FLOYD ROUTING ******************************** */
1346 #define TO_FLOYD_COST(i,j) (routing->cost_table)[(i)+(j)*table_size]
1347 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
1348 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
1350 /* Routing model structure */
1353 s_routing_component_t generic_routing;
1354 /* vars for calculate the floyd algorith. */
1355 int *predecessor_table;
1357 route_extended_t *link_table; /* char* -> int* */
1358 } s_routing_component_floyd_t, *routing_component_floyd_t;
1360 static route_extended_t floyd_get_route(routing_component_t rc,
1361 const char *src, const char *dst);
1363 /* Business methods */
1364 static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
1366 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1368 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1369 //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1370 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1371 char *k1, *d1, *k2, *d2;
1372 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1373 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1374 route_extended_t route = floyd_get_route(rc, k1, k2);
1376 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1378 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1380 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1381 onelink->link_ptr = link;
1382 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1383 onelink->src = xbt_strdup(k1);
1384 onelink->dst = xbt_strdup(k2);
1385 } else if (routing->generic_routing.hierarchy ==
1386 SURF_ROUTING_RECURSIVE) {
1387 onelink->src = xbt_strdup(route->src_gateway);
1388 onelink->dst = xbt_strdup(route->dst_gateway);
1390 xbt_dynar_push(ret, &onelink);
1398 static route_extended_t floyd_get_route(routing_component_t rc,
1399 const char *src, const char *dst)
1401 xbt_assert1(rc && src
1403 "Invalid params for \"get_route\" function at AS \"%s\"",
1406 /* set utils vars */
1407 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1408 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1410 generic_src_dst_check(rc, src, dst);
1411 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1412 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1415 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1418 /* create a result route */
1419 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1420 new_e_route->generic_route.link_list =
1421 xbt_dynar_new(global_routing->size_of_link, NULL);
1422 new_e_route->src_gateway = NULL;
1423 new_e_route->dst_gateway = NULL;
1428 char *gw_src = NULL, *gw_dst =
1429 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1436 pred = TO_FLOYD_PRED(*src_id, pred);
1437 if (pred == -1) /* if no pred in route -> no route to host */
1439 xbt_assert2(TO_FLOYD_LINK(pred, prev_pred),
1440 "Invalid link for the route between \"%s\" or \"%s\"", src,
1443 prev_gw_src = gw_src;
1444 prev_gw_dst = gw_dst;
1446 route_extended_t e_route = TO_FLOYD_LINK(pred, prev_pred);
1447 gw_src = e_route->src_gateway;
1448 gw_dst = e_route->dst_gateway;
1453 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && !first
1454 && strcmp(gw_dst, prev_gw_src)) {
1455 xbt_dynar_t e_route_as_to_as =
1456 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1457 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1458 gw_dst, prev_gw_src);
1459 links = e_route_as_to_as;
1461 xbt_dynar_foreach(links, cpt, link) {
1462 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1468 links = e_route->generic_route.link_list;
1469 xbt_dynar_foreach(links, cpt, link) {
1470 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1474 } while (pred != *src_id);
1475 xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")",
1476 *src_id, *dst_id, src, dst);
1478 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1479 new_e_route->src_gateway = xbt_strdup(gw_src);
1480 new_e_route->dst_gateway = xbt_strdup(first_gw);
1486 static void floyd_finalize(routing_component_t rc)
1488 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1492 table_size = xbt_dict_length(routing->generic_routing.to_index);
1493 /* Delete link_table */
1494 for (i = 0; i < table_size; i++)
1495 for (j = 0; j < table_size; j++)
1496 generic_free_extended_route(TO_FLOYD_LINK(i, j));
1497 xbt_free(routing->link_table);
1498 /* Delete bypass dict */
1499 xbt_dict_free(&routing->generic_routing.bypassRoutes);
1500 /* Delete index dict */
1501 xbt_dict_free(&(routing->generic_routing.to_index));
1502 /* Delete dictionary index dict, predecessor and links table */
1503 xbt_free(routing->predecessor_table);
1504 /* Delete structure */
1509 static void *model_floyd_create(void)
1511 routing_component_floyd_t new_component =
1512 xbt_new0(s_routing_component_floyd_t, 1);
1513 new_component->generic_routing.set_processing_unit =
1514 generic_set_processing_unit;
1515 new_component->generic_routing.set_autonomous_system =
1516 generic_set_autonomous_system;
1517 new_component->generic_routing.set_route = model_floyd_set_route;
1518 new_component->generic_routing.set_ASroute = model_floyd_set_route;
1519 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1520 new_component->generic_routing.get_route = floyd_get_route;
1521 new_component->generic_routing.get_latency = generic_get_link_latency;
1522 new_component->generic_routing.get_onelink_routes =
1523 floyd_get_onelink_routes;
1524 new_component->generic_routing.get_bypass_route =
1525 generic_get_bypassroute;
1526 new_component->generic_routing.finalize = floyd_finalize;
1527 new_component->generic_routing.to_index = xbt_dict_new();
1528 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1529 return new_component;
1532 static void model_floyd_load(void)
1534 /* use "surfxml_add_callback" to add a parse function call */
1537 static void model_floyd_unload(void)
1539 /* use "surfxml_del_callback" to remove a parse function call */
1542 static void model_floyd_end(void)
1545 routing_component_floyd_t routing =
1546 ((routing_component_floyd_t) current_routing);
1548 unsigned int i, j, a, b, c;
1550 /* set the size of table routing */
1551 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1553 if(!routing->link_table)
1555 /* Create Cost, Predecessor and Link tables */
1556 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1557 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1558 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1560 /* Initialize costs and predecessors */
1561 for (i = 0; i < table_size; i++)
1562 for (j = 0; j < table_size; j++) {
1563 TO_FLOYD_COST(i, j) = DBL_MAX;
1564 TO_FLOYD_PRED(i, j) = -1;
1565 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1569 /* Add the loopback if needed */
1570 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1571 for (i = 0; i < table_size; i++) {
1572 route_extended_t e_route = TO_FLOYD_LINK(i, i);
1574 e_route = xbt_new0(s_route_extended_t, 1);
1575 e_route->src_gateway = NULL;
1576 e_route->dst_gateway = NULL;
1577 e_route->generic_route.link_list =
1578 xbt_dynar_new(global_routing->size_of_link, NULL);
1579 xbt_dynar_push(e_route->generic_route.link_list,
1580 &global_routing->loopback);
1581 TO_FLOYD_LINK(i, i) = e_route;
1582 TO_FLOYD_PRED(i, i) = i;
1583 TO_FLOYD_COST(i, i) = 1;
1587 /* Calculate path costs */
1588 for (c = 0; c < table_size; c++) {
1589 for (a = 0; a < table_size; a++) {
1590 for (b = 0; b < table_size; b++) {
1591 if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
1592 if (TO_FLOYD_COST(a, b) == DBL_MAX ||
1593 (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
1594 TO_FLOYD_COST(a, b))) {
1595 TO_FLOYD_COST(a, b) =
1596 TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
1597 TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
1605 static void model_floyd_set_route(routing_component_t rc, const char *src,
1606 const char *dst, name_route_extended_t route)
1608 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1610 /* set the size of table routing */
1611 size_t table_size = xbt_dict_length(rc->to_index);
1612 int *src_id, *dst_id;
1615 src_id = xbt_dict_get_or_null(rc->to_index, src);
1616 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1618 if(!routing->link_table)
1620 /* Create Cost, Predecessor and Link tables */
1621 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1622 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1623 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1625 /* Initialize costs and predecessors */
1626 for (i = 0; i < table_size; i++)
1627 for (j = 0; j < table_size; j++) {
1628 TO_FLOYD_COST(i, j) = DBL_MAX;
1629 TO_FLOYD_PRED(i, j) = -1;
1630 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1634 if(TO_FLOYD_LINK(*src_id, *dst_id))
1636 if(!route->dst_gateway && !route->src_gateway)
1637 DEBUG2("See Route from \"%s\" to \"%s\"", src, dst);
1639 DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1640 route->src_gateway, dst, route->dst_gateway);
1643 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1644 xbt_dynar_foreach(route->generic_route.link_list,cpt,link_name)
1646 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1647 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1648 xbt_dynar_push(link_route_to_test,&link);
1650 xbt_assert2(!xbt_dynar_compare(
1651 (void*)TO_FLOYD_LINK(*src_id, *dst_id)->generic_route.link_list,
1652 (void*)link_route_to_test,
1653 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1654 "The route between \"%s\" and \"%s\" already exists", src,dst);
1655 xbt_free(link_route_to_test);
1659 if(!route->dst_gateway && !route->src_gateway)
1660 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1662 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1663 route->src_gateway, dst, route->dst_gateway);
1665 TO_FLOYD_LINK(*src_id, *dst_id) =
1666 generic_new_extended_route(rc->hierarchy, route, 1);
1667 TO_FLOYD_PRED(*src_id, *dst_id) = *src_id;
1668 TO_FLOYD_COST(*src_id, *dst_id) =
1669 ((TO_FLOYD_LINK(*src_id, *dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1672 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1673 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1675 if(TO_FLOYD_LINK(*dst_id, *src_id))
1677 if(!route->dst_gateway && !route->src_gateway)
1678 DEBUG2("See Route from \"%s\" to \"%s\"", dst, src);
1680 DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1681 route->src_gateway, src, route->dst_gateway);
1684 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1685 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1687 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1688 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1689 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1690 xbt_dynar_push(link_route_to_test,&link);
1692 xbt_assert2(!xbt_dynar_compare(
1693 (void*)TO_FLOYD_LINK(*dst_id, *src_id)->generic_route.link_list,
1694 (void*)link_route_to_test,
1695 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1696 "The route between \"%s\" and \"%s\" already exists", src,dst);
1697 xbt_free(link_route_to_test);
1701 if(route->dst_gateway && route->src_gateway)
1703 char *gw_src = xbt_strdup(route->src_gateway);
1704 char *gw_dst = xbt_strdup(route->dst_gateway);
1705 route->src_gateway = gw_dst;
1706 route->dst_gateway = gw_src;
1709 if(!route->dst_gateway && !route->src_gateway)
1710 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1712 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1713 route->src_gateway, src, route->dst_gateway);
1715 TO_FLOYD_LINK(*dst_id, *src_id) =
1716 generic_new_extended_route(rc->hierarchy, route, 0);
1717 TO_FLOYD_PRED(*dst_id, *src_id) = *dst_id;
1718 TO_FLOYD_COST(*dst_id, *src_id) =
1719 ((TO_FLOYD_LINK(*dst_id, *src_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1724 /* ************************************************************************** */
1725 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1728 s_routing_component_t generic_routing;
1729 xbt_graph_t route_graph; /* xbt_graph */
1730 xbt_dict_t graph_node_map; /* map */
1731 xbt_dict_t route_cache; /* use in cache mode */
1733 } s_routing_component_dijkstra_t, *routing_component_dijkstra_t;
1736 typedef struct graph_node_data {
1738 int graph_id; /* used for caching internal graph id's */
1739 } s_graph_node_data_t, *graph_node_data_t;
1741 typedef struct graph_node_map_element {
1743 } s_graph_node_map_element_t, *graph_node_map_element_t;
1745 typedef struct route_cache_element {
1748 } s_route_cache_element_t, *route_cache_element_t;
1750 /* Free functions */
1752 static void route_cache_elem_free(void *e)
1754 route_cache_element_t elm = (route_cache_element_t) e;
1756 xbt_free(elm->pred_arr);
1761 static void graph_node_map_elem_free(void *e)
1763 graph_node_map_element_t elm = (graph_node_map_element_t) e;
1769 static void graph_edge_data_free(void *e)
1771 route_extended_t e_route = (route_extended_t) e;
1773 xbt_dynar_free(&(e_route->generic_route.link_list));
1774 if (e_route->src_gateway)
1775 xbt_free(e_route->src_gateway);
1776 if (e_route->dst_gateway)
1777 xbt_free(e_route->dst_gateway);
1782 /* Utility functions */
1784 static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc,
1785 int id, int graph_id)
1787 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1788 xbt_node_t node = NULL;
1789 graph_node_data_t data = NULL;
1790 graph_node_map_element_t elm = NULL;
1792 data = xbt_new0(struct graph_node_data, 1);
1794 data->graph_id = graph_id;
1795 node = xbt_graph_new_node(routing->route_graph, data);
1797 elm = xbt_new0(struct graph_node_map_element, 1);
1799 xbt_dict_set_ext(routing->graph_node_map, (char *) (&id), sizeof(int),
1800 (xbt_set_elm_t) elm, &graph_node_map_elem_free);
1805 static graph_node_map_element_t
1806 graph_node_map_search(routing_component_dijkstra_t rc, int id)
1808 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1809 graph_node_map_element_t elm = (graph_node_map_element_t)
1810 xbt_dict_get_or_null_ext(routing->graph_node_map,
1818 static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id,
1819 int dst_id, route_extended_t e_route)
1821 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1823 xbt_node_t src = NULL;
1824 xbt_node_t dst = NULL;
1825 graph_node_map_element_t src_elm = (graph_node_map_element_t)
1826 xbt_dict_get_or_null_ext(routing->graph_node_map,
1829 graph_node_map_element_t dst_elm = (graph_node_map_element_t)
1830 xbt_dict_get_or_null_ext(routing->graph_node_map,
1835 src = src_elm->node;
1838 dst = dst_elm->node;
1840 /* add nodes if they don't exist in the graph */
1841 if (src_id == dst_id && src == NULL && dst == NULL) {
1842 src = route_graph_new_node(rc, src_id, -1);
1846 src = route_graph_new_node(rc, src_id, -1);
1849 dst = route_graph_new_node(rc, dst_id, -1);
1853 /* add link as edge to graph */
1854 xbt_graph_new_edge(routing->route_graph, src, dst, e_route);
1857 static void add_loopback_dijkstra(routing_component_dijkstra_t rc)
1859 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1861 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1863 xbt_node_t node = NULL;
1864 unsigned int cursor2;
1865 xbt_dynar_foreach(nodes, cursor2, node) {
1866 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1867 xbt_edge_t edge = NULL;
1868 unsigned int cursor;
1871 xbt_dynar_foreach(out_edges, cursor, edge) {
1872 xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1873 if (other_node == node) {
1880 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
1881 e_route->src_gateway = NULL;
1882 e_route->dst_gateway = NULL;
1883 e_route->generic_route.link_list =
1884 xbt_dynar_new(global_routing->size_of_link, NULL);
1885 xbt_dynar_push(e_route->generic_route.link_list,
1886 &global_routing->loopback);
1887 xbt_graph_new_edge(routing->route_graph, node, node, e_route);
1892 /* Business methods */
1893 static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
1895 xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
1898 static route_extended_t dijkstra_get_route(routing_component_t rc,
1902 xbt_assert1(rc && src
1904 "Invalid params for \"get_route\" function at AS \"%s\"",
1907 /* set utils vars */
1908 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1910 generic_src_dst_check(rc, src, dst);
1911 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1912 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1915 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1918 /* create a result route */
1919 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1920 new_e_route->generic_route.link_list =
1921 xbt_dynar_new(global_routing->size_of_link, NULL);
1922 new_e_route->src_gateway = NULL;
1923 new_e_route->dst_gateway = NULL;
1925 int *pred_arr = NULL;
1926 int src_node_id = 0;
1927 int dst_node_id = 0;
1930 route_extended_t e_route;
1934 xbt_dynar_t links = NULL;
1935 route_cache_element_t elm = NULL;
1936 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1938 /* Use the graph_node id mapping set to quickly find the nodes */
1939 graph_node_map_element_t src_elm =
1940 graph_node_map_search(routing, *src_id);
1941 graph_node_map_element_t dst_elm =
1942 graph_node_map_search(routing, *dst_id);
1943 xbt_assert2(src_elm != NULL
1944 && dst_elm != NULL, "src %d or dst %d does not exist",
1946 src_node_id = ((graph_node_data_t)
1947 xbt_graph_node_get_data(src_elm->node))->graph_id;
1948 dst_node_id = ((graph_node_data_t)
1949 xbt_graph_node_get_data(dst_elm->node))->graph_id;
1951 /* if the src and dst are the same *//* fixed, missing in the previous version */
1952 if (src_node_id == dst_node_id) {
1954 xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
1955 xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
1957 xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v);
1959 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
1962 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
1964 links = e_route->generic_route.link_list;
1965 xbt_dynar_foreach(links, cpt, link) {
1966 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1972 if (routing->cached) {
1973 /*check if there is a cached predecessor list avail */
1974 elm = (route_cache_element_t)
1975 xbt_dict_get_or_null_ext(routing->route_cache, (char *) (&src_id),
1979 if (elm) { /* cached mode and cache hit */
1980 pred_arr = elm->pred_arr;
1981 } else { /* not cached mode or cache miss */
1982 double *cost_arr = NULL;
1983 xbt_heap_t pqueue = NULL;
1986 int nr_nodes = xbt_dynar_length(nodes);
1987 cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
1988 pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
1989 pqueue = xbt_heap_new(nr_nodes, xbt_free);
1992 cost_arr[src_node_id] = 0.0;
1994 for (i = 0; i < nr_nodes; i++) {
1995 if (i != src_node_id) {
1996 cost_arr[i] = DBL_MAX;
2001 /* initialize priority queue */
2002 nodeid = xbt_new0(int, 1);
2004 xbt_heap_push(pqueue, nodeid, cost_arr[i]);
2008 /* apply dijkstra using the indexes from the graph's node array */
2009 while (xbt_heap_size(pqueue) > 0) {
2010 int *v_id = xbt_heap_pop(pqueue);
2011 xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
2012 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
2013 xbt_edge_t edge = NULL;
2014 unsigned int cursor;
2016 xbt_dynar_foreach(out_edges, cursor, edge) {
2017 xbt_node_t u_node = xbt_graph_edge_get_target(edge);
2018 graph_node_data_t data = xbt_graph_node_get_data(u_node);
2019 int u_id = data->graph_id;
2020 route_extended_t tmp_e_route =
2021 (route_extended_t) xbt_graph_edge_get_data(edge);
2022 int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */
2024 if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
2025 pred_arr[u_id] = *v_id;
2026 cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
2027 nodeid = xbt_new0(int, 1);
2029 xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
2033 /* free item popped from pqueue */
2038 xbt_heap_free(pqueue);
2041 /* compose route path with links */
2042 char *gw_src = NULL, *gw_dst =
2043 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
2045 for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
2046 xbt_node_t node_pred_v =
2047 xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
2048 xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
2050 xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
2052 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
2055 prev_gw_src = gw_src;
2056 prev_gw_dst = gw_dst;
2058 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
2059 gw_src = e_route->src_gateway;
2060 gw_dst = e_route->dst_gateway;
2062 if (v == dst_node_id)
2065 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
2066 && strcmp(gw_dst, prev_gw_src)) {
2067 xbt_dynar_t e_route_as_to_as =
2068 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
2069 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
2070 gw_dst, prev_gw_src);
2071 links = e_route_as_to_as;
2073 xbt_dynar_foreach(links, cpt, link) {
2074 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
2080 links = e_route->generic_route.link_list;
2081 xbt_dynar_foreach(links, cpt, link) {
2082 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
2087 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
2088 new_e_route->src_gateway = xbt_strdup(gw_src);
2089 new_e_route->dst_gateway = xbt_strdup(first_gw);
2092 if (routing->cached && elm == NULL) {
2093 /* add to predecessor list of the current src-host to cache */
2094 elm = xbt_new0(struct route_cache_element, 1);
2095 elm->pred_arr = pred_arr;
2097 xbt_dict_set_ext(routing->route_cache, (char *) (&src_id), sizeof(int),
2098 (xbt_set_elm_t) elm, &route_cache_elem_free);
2101 if (!routing->cached)
2107 static void dijkstra_finalize(routing_component_t rc)
2109 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2112 xbt_graph_free_graph(routing->route_graph, &xbt_free,
2113 &graph_edge_data_free, &xbt_free);
2114 xbt_dict_free(&routing->graph_node_map);
2115 if (routing->cached)
2116 xbt_dict_free(&routing->route_cache);
2117 /* Delete bypass dict */
2118 xbt_dict_free(&routing->generic_routing.bypassRoutes);
2119 /* Delete index dict */
2120 xbt_dict_free(&(routing->generic_routing.to_index));
2121 /* Delete structure */
2126 /* Creation routing model functions */
2128 static void *model_dijkstra_both_create(int cached)
2130 routing_component_dijkstra_t new_component =
2131 xbt_new0(s_routing_component_dijkstra_t, 1);
2132 new_component->generic_routing.set_processing_unit =
2133 generic_set_processing_unit;
2134 new_component->generic_routing.set_autonomous_system =
2135 generic_set_autonomous_system;
2136 new_component->generic_routing.set_route = model_dijkstra_both_set_route;
2137 new_component->generic_routing.set_ASroute = model_dijkstra_both_set_route; //TODO
2138 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
2139 new_component->generic_routing.get_route = dijkstra_get_route;
2140 new_component->generic_routing.get_latency = generic_get_link_latency;
2141 new_component->generic_routing.get_onelink_routes =
2142 dijkstra_get_onelink_routes;
2143 new_component->generic_routing.get_bypass_route =
2144 generic_get_bypassroute;
2145 new_component->generic_routing.finalize = dijkstra_finalize;
2146 new_component->cached = cached;
2147 new_component->generic_routing.to_index = xbt_dict_new();
2148 new_component->generic_routing.bypassRoutes = xbt_dict_new();
2149 return new_component;
2152 static void *model_dijkstra_create(void)
2154 return model_dijkstra_both_create(0);
2157 static void *model_dijkstracache_create(void)
2159 return model_dijkstra_both_create(1);
2162 static void model_dijkstra_both_load(void)
2164 /* use "surfxml_add_callback" to add a parse function call */
2167 static void model_dijkstra_both_unload(void)
2169 /* use "surfxml_del_callback" to remove a parse function call */
2172 static void model_dijkstra_both_end(void)
2174 routing_component_dijkstra_t routing =
2175 (routing_component_dijkstra_t) current_routing;
2177 xbt_node_t node = NULL;
2178 unsigned int cursor2;
2179 xbt_dynar_t nodes = NULL;
2181 /* Create the topology graph */
2182 routing->route_graph = xbt_graph_new_graph(1, NULL);
2183 routing->graph_node_map = xbt_dict_new();
2185 if (routing->cached && !routing->route_cache)
2186 routing->route_cache = xbt_dict_new();
2188 /* Add the loopback if needed */
2189 if (current_routing->hierarchy == SURF_ROUTING_BASE)
2190 add_loopback_dijkstra(routing);
2192 /* initialize graph indexes in nodes after graph has been built */
2193 nodes = xbt_graph_get_nodes(routing->route_graph);
2195 xbt_dynar_foreach(nodes, cursor2, node) {
2196 graph_node_data_t data = xbt_graph_node_get_data(node);
2197 data->graph_id = cursor2;
2201 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
2202 const char *dst, name_route_extended_t route)
2204 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2205 int *src_id, *dst_id;
2206 src_id = xbt_dict_get_or_null(rc->to_index, src);
2207 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
2209 if (routing->cached && !routing->route_cache)
2210 routing->route_cache = xbt_dict_new();
2212 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
2213 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
2214 xbt_die("Route symmetrical not supported on model dijkstra");
2216 if(!route->dst_gateway && !route->src_gateway)
2217 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
2219 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
2220 route->src_gateway, dst, route->dst_gateway);
2222 route_extended_t e_route =
2223 generic_new_extended_route(current_routing->hierarchy, route, 1);
2224 route_new_dijkstra(routing, *src_id, *dst_id, e_route);
2227 #ifdef HAVE_PCRE_LIB
2228 /* ************************************************** */
2229 /* ************** RULE-BASED ROUTING **************** */
2231 /* Routing model structure */
2234 s_routing_component_t generic_routing;
2235 xbt_dict_t dict_processing_units;
2236 xbt_dict_t dict_autonomous_systems;
2237 xbt_dynar_t list_route;
2238 xbt_dynar_t list_ASroute;
2239 } s_routing_component_rulebased_t, *routing_component_rulebased_t;
2241 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
2242 typedef struct s_rule_route_extended s_rule_route_extended_t,
2243 *rule_route_extended_t;
2245 struct s_rule_route {
2246 xbt_dynar_t re_str_link; // dynar of char*
2251 struct s_rule_route_extended {
2252 s_rule_route_t generic_rule_route;
2253 char *re_src_gateway;
2254 char *re_dst_gateway;
2257 static void rule_route_free(void *e)
2259 rule_route_t *elem = (rule_route_t *) (e);
2261 xbt_dynar_free(&(*elem)->re_str_link);
2262 pcre_free((*elem)->re_src);
2263 pcre_free((*elem)->re_dst);
2269 static void rule_route_extended_free(void *e)
2271 rule_route_extended_t *elem = (rule_route_extended_t *) e;
2273 xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link);
2274 pcre_free((*elem)->generic_rule_route.re_src);
2275 pcre_free((*elem)->generic_rule_route.re_dst);
2276 xbt_free((*elem)->re_src_gateway);
2277 xbt_free((*elem)->re_dst_gateway);
2282 /* Parse routing model functions */
2284 static void model_rulebased_set_processing_unit(routing_component_t rc,
2287 routing_component_rulebased_t routing =
2288 (routing_component_rulebased_t) rc;
2289 xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
2292 static void model_rulebased_set_autonomous_system(routing_component_t rc,
2295 routing_component_rulebased_t routing =
2296 (routing_component_rulebased_t) rc;
2297 xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
2301 static void model_rulebased_set_route(routing_component_t rc,
2302 const char *src, const char *dst,
2303 name_route_extended_t route)
2305 routing_component_rulebased_t routing =
2306 (routing_component_rulebased_t) rc;
2307 rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
2310 ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL);
2311 xbt_assert3(ruleroute->re_src,
2312 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2313 erroffset, src, error);
2314 ruleroute->re_dst = pcre_compile(dst, 0, &error, &erroffset, NULL);
2315 xbt_assert3(ruleroute->re_src,
2316 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2317 erroffset, dst, error);
2318 ruleroute->re_str_link = route->generic_route.link_list;
2319 xbt_dynar_push(routing->list_route, &ruleroute);
2323 static void model_rulebased_set_ASroute(routing_component_t rc,
2324 const char *src, const char *dst,
2325 name_route_extended_t route)
2327 routing_component_rulebased_t routing =
2328 (routing_component_rulebased_t) rc;
2329 rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
2332 ruleroute_e->generic_rule_route.re_src =
2333 pcre_compile(src, 0, &error, &erroffset, NULL);
2334 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2335 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2336 erroffset, src, error);
2337 ruleroute_e->generic_rule_route.re_dst =
2338 pcre_compile(dst, 0, &error, &erroffset, NULL);
2339 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2340 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2341 erroffset, dst, error);
2342 ruleroute_e->generic_rule_route.re_str_link =
2343 route->generic_route.link_list;
2344 ruleroute_e->re_src_gateway = route->src_gateway;
2345 ruleroute_e->re_dst_gateway = route->dst_gateway;
2346 xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
2347 xbt_free(route->src_gateway);
2348 xbt_free(route->dst_gateway);
2352 static void model_rulebased_set_bypassroute(routing_component_t rc,
2355 route_extended_t e_route)
2357 xbt_die("bypass routing not supported for Route-Based model");
2360 #define BUFFER_SIZE 4096 /* result buffer size */
2361 #define OVECCOUNT 30 /* should be a multiple of 3 */
2363 static char *remplace(char *value, const char **src_list, int src_size,
2364 const char **dst_list, int dst_size)
2367 char result_result[BUFFER_SIZE];
2368 int i_result_buffer;
2369 int value_length = (int) strlen(value);
2373 i_result_buffer = 0;
2375 if (value[i] == '$') {
2379 int number_length = 0;
2380 while ('0' <= value[i + number_length]
2381 && value[i + number_length] <= '9') {
2384 xbt_assert2(number_length != 0,
2385 "bad string parameter, no number indication, at offset: %d (\"%s\")",
2389 number = atoi(value + i);
2390 i = i + number_length;
2391 xbt_assert2(i + 2 < value_length,
2392 "bad string parameter, too few chars, at offset: %d (\"%s\")",
2395 // solve the indication
2396 const char **param_list;
2398 if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') {
2399 param_list = src_list;
2400 param_size = src_size;
2401 } else if (value[i] == 'd' && value[i + 1] == 's'
2402 && value[i + 2] == 't') {
2403 param_list = dst_list;
2404 param_size = dst_size;
2407 "bad string parameter, support only \"src\" and \"dst\", at offset: %d (\"%s\")",
2412 xbt_assert4(param_size >= number,
2413 "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",
2414 i, value, param_size, number);
2416 const char *param = param_list[number];
2417 int size = strlen(param);
2419 for (cp = 0; cp < size; cp++) {
2420 result_result[i_result_buffer] = param[cp];
2422 if (i_result_buffer >= BUFFER_SIZE)
2426 result_result[i_result_buffer] = value[i];
2431 } while (i < value_length && i_result_buffer < BUFFER_SIZE);
2433 xbt_assert2(i_result_buffer < BUFFER_SIZE,
2434 "solving string \"%s\", small buffer size (%d)", value,
2436 result_result[i_result_buffer] = 0;
2437 return xbt_strdup(result_result);
2440 static route_extended_t rulebased_get_route(routing_component_t rc,
2443 static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
2445 xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
2446 routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
2448 xbt_dict_cursor_t c1 = NULL;
2452 char *router = NULL;
2453 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2454 if (strstr (k1, "router")){
2459 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2462 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2463 route_extended_t route = rulebased_get_route (rc, router, k1);
2465 int number_of_links = xbt_dynar_length(route->generic_route.link_list);
2466 if (number_of_links != 3) {
2467 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2471 xbt_dynar_get_cpy (route->generic_route.link_list, 2, &link_ptr);
2472 onelink_t onelink = xbt_new0 (s_onelink_t, 1);
2473 onelink->src = xbt_strdup (k1);
2474 onelink->dst = xbt_strdup (router);
2475 onelink->link_ptr = link_ptr;
2476 xbt_dynar_push (ret, &onelink);
2481 /* Business methods */
2482 static route_extended_t rulebased_get_route(routing_component_t rc,
2486 xbt_assert1(rc && src
2488 "Invalid params for \"get_route\" function at AS \"%s\"",
2491 /* set utils vars */
2492 routing_component_rulebased_t routing =
2493 (routing_component_rulebased_t) rc;
2495 int are_processing_units;
2496 xbt_dynar_t rule_list;
2497 if (xbt_dict_get_or_null(routing->dict_processing_units, src)
2498 && xbt_dict_get_or_null(routing->dict_processing_units, dst)) {
2499 are_processing_units = 1;
2500 rule_list = routing->list_route;
2501 } else if (xbt_dict_get_or_null(routing->dict_autonomous_systems, src)
2502 && xbt_dict_get_or_null(routing->dict_autonomous_systems,
2504 are_processing_units = 0;
2505 rule_list = routing->list_ASroute;
2508 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
2513 int src_length = (int) strlen(src);
2514 int dst_length = (int) strlen(dst);
2516 xbt_dynar_t links_list =
2517 xbt_dynar_new(global_routing->size_of_link, NULL);
2519 rule_route_t ruleroute;
2521 int ovector_src[OVECCOUNT];
2522 int ovector_dst[OVECCOUNT];
2523 const char **list_src = NULL;
2524 const char **list_dst = NULL;
2525 xbt_dynar_foreach(rule_list, cpt, ruleroute) {
2527 pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0,
2528 ovector_src, OVECCOUNT);
2531 pcre_exec(ruleroute->re_dst, NULL, dst, dst_length, 0, 0,
2532 ovector_dst, OVECCOUNT);
2534 xbt_assert1(!pcre_get_substring_list
2535 (src, ovector_src, rc_src, &list_src),
2536 "error solving substring list for src \"%s\"", src);
2537 xbt_assert1(!pcre_get_substring_list
2538 (dst, ovector_dst, rc_dst, &list_dst),
2539 "error solving substring list for src \"%s\"", dst);
2541 xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) {
2542 char *new_link_name =
2543 remplace(link_name, list_src, rc_src, list_dst, rc_dst);
2545 xbt_dict_get_or_null(surf_network_model->resource_set,
2548 xbt_dynar_push(links_list, &link);
2550 THROW1(mismatch_error, 0, "Link %s not found", new_link_name);
2551 xbt_free(new_link_name);
2555 if (rc_src >= 0 && rc_dst >= 0)
2559 route_extended_t new_e_route = NULL;
2560 if (rc_src >= 0 && rc_dst >= 0) {
2561 new_e_route = xbt_new0(s_route_extended_t, 1);
2562 new_e_route->generic_route.link_list = links_list;
2563 } else if (!strcmp(src, dst) && are_processing_units) {
2564 new_e_route = xbt_new0(s_route_extended_t, 1);
2565 xbt_dynar_push(links_list, &(global_routing->loopback));
2566 new_e_route->generic_route.link_list = links_list;
2568 xbt_dynar_free(&link_list);
2571 if (!are_processing_units && new_e_route) {
2572 rule_route_extended_t ruleroute_extended =
2573 (rule_route_extended_t) ruleroute;
2574 new_e_route->src_gateway =
2575 remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
2577 new_e_route->dst_gateway =
2578 remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
2583 pcre_free_substring_list(list_src);
2585 pcre_free_substring_list(list_dst);
2590 static route_extended_t rulebased_get_bypass_route(routing_component_t rc,
2597 static void rulebased_finalize(routing_component_t rc)
2599 routing_component_rulebased_t routing =
2600 (routing_component_rulebased_t) rc;
2602 xbt_dict_free(&routing->dict_processing_units);
2603 xbt_dict_free(&routing->dict_autonomous_systems);
2604 xbt_dynar_free(&routing->list_route);
2605 xbt_dynar_free(&routing->list_ASroute);
2606 /* Delete structure */
2611 /* Creation routing model functions */
2612 static void *model_rulebased_create(void)
2614 routing_component_rulebased_t new_component =
2615 xbt_new0(s_routing_component_rulebased_t, 1);
2616 new_component->generic_routing.set_processing_unit =
2617 model_rulebased_set_processing_unit;
2618 new_component->generic_routing.set_autonomous_system =
2619 model_rulebased_set_autonomous_system;
2620 new_component->generic_routing.set_route = model_rulebased_set_route;
2621 new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
2622 new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
2623 new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
2624 new_component->generic_routing.get_route = rulebased_get_route;
2625 new_component->generic_routing.get_bypass_route = generic_get_bypassroute; //rulebased_get_bypass_route;
2626 new_component->generic_routing.finalize = rulebased_finalize;
2627 /* initialization of internal structures */
2628 new_component->dict_processing_units = xbt_dict_new();
2629 new_component->dict_autonomous_systems = xbt_dict_new();
2630 new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
2631 new_component->list_ASroute =
2632 xbt_dynar_new(sizeof(rule_route_extended_t),
2633 &rule_route_extended_free);
2634 return new_component;
2637 static void model_rulebased_load(void)
2639 /* use "surfxml_add_callback" to add a parse function call */
2642 static void model_rulebased_unload(void)
2644 /* use "surfxml_del_callback" to remove a parse function call */
2647 static void model_rulebased_end(void)
2651 #endif /* HAVE_PCRE_LIB */
2653 /* ************************************************************************** */
2654 /* ******************************* NO ROUTING ******************************* */
2656 /* Routing model structure */
2658 s_routing_component_t generic_routing;
2659 } s_routing_component_none_t, *routing_component_none_t;
2661 /* Business methods */
2662 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc)
2667 static route_extended_t none_get_route(routing_component_t rc,
2668 const char *src, const char *dst)
2673 static route_extended_t none_get_bypass_route(routing_component_t rc,
2680 static void none_finalize(routing_component_t rc)
2685 static void none_set_processing_unit(routing_component_t rc,
2690 static void none_set_autonomous_system(routing_component_t rc,
2695 /* Creation routing model functions */
2696 static void *model_none_create(void)
2698 routing_component_none_t new_component =
2699 xbt_new0(s_routing_component_none_t, 1);
2700 new_component->generic_routing.set_processing_unit =
2701 none_set_processing_unit;
2702 new_component->generic_routing.set_autonomous_system =
2703 none_set_autonomous_system;
2704 new_component->generic_routing.set_route = NULL;
2705 new_component->generic_routing.set_ASroute = NULL;
2706 new_component->generic_routing.set_bypassroute = NULL;
2707 new_component->generic_routing.get_route = none_get_route;
2708 new_component->generic_routing.get_onelink_routes =
2709 none_get_onelink_routes;
2710 new_component->generic_routing.get_bypass_route = none_get_bypass_route;
2711 new_component->generic_routing.finalize = none_finalize;
2712 return new_component;
2715 static void model_none_load(void)
2719 static void model_none_unload(void)
2723 static void model_none_end(void)
2727 /* ************************************************** */
2728 /* ********** PATERN FOR NEW ROUTING **************** */
2730 /* The minimal configuration of a new routing model need the next functions,
2731 * also you need to set at the start of the file, the new model in the model
2732 * list. Remember keep the null ending of the list.
2734 /*** Routing model structure ***/
2736 // s_routing_component_t generic_routing;
2737 // /* things that your routing model need */
2738 // } s_routing_component_NEW_t,*routing_component_NEW_t;
2740 /*** Parse routing model functions ***/
2741 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
2742 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
2743 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
2744 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
2745 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
2747 /*** Business methods ***/
2748 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2749 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2750 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
2752 /*** Creation routing model functions ***/
2753 // static void* model_NEW_create(void) {
2754 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
2755 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
2756 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
2757 // new_component->generic_routing.set_route = model_NEW_set_route;
2758 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
2759 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
2760 // new_component->generic_routing.get_route = NEW_get_route;
2761 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
2762 // new_component->generic_routing.finalize = NEW_finalize;
2763 // /* initialization of internal structures */
2764 // return new_component;
2765 // } /* mandatory */
2766 // static void model_NEW_load(void) {} /* mandatory */
2767 // static void model_NEW_unload(void) {} /* mandatory */
2768 // static void model_NEW_end(void) {} /* mandatory */
2770 /* ************************************************************************** */
2771 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
2773 static void generic_set_processing_unit(routing_component_t rc,
2776 DEBUG1("Load process unit \"%s\"", name);
2777 int *id = xbt_new0(int, 1);
2778 xbt_dict_t _to_index;
2779 _to_index = current_routing->to_index;
2780 *id = xbt_dict_length(_to_index);
2781 xbt_dict_set(_to_index, name, id, xbt_free);
2784 static void generic_set_autonomous_system(routing_component_t rc,
2787 DEBUG1("Load Autonomous system \"%s\"", name);
2788 int *id = xbt_new0(int, 1);
2789 xbt_dict_t _to_index;
2790 _to_index = current_routing->to_index;
2791 *id = xbt_dict_length(_to_index);
2792 xbt_dict_set(_to_index, name, id, xbt_free);
2795 static int surf_pointer_resource_cmp(const void *a, const void *b)
2800 static int surf_link_resource_cmp(const void *a, const void *b)
2802 return !!memcmp(a,b,global_routing->size_of_link);
2805 static void generic_set_bypassroute(routing_component_t rc,
2806 const char *src, const char *dst,
2807 route_extended_t e_route)
2809 DEBUG2("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
2810 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2813 route_name = bprintf("%s#%s", src, dst);
2814 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2815 "Invalid count of links, must be greater than zero (%s,%s)",
2817 xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
2818 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
2819 src, e_route->src_gateway, dst, e_route->dst_gateway);
2821 route_extended_t new_e_route =
2822 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
2823 xbt_dynar_free(&(e_route->generic_route.link_list));
2826 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
2827 (void (*)(void *)) generic_free_extended_route);
2828 xbt_free(route_name);
2831 /* ************************************************************************** */
2832 /* *********************** GENERIC BUSINESS METHODS ************************* */
2834 static double generic_get_link_latency(routing_component_t rc,
2835 const char *src, const char *dst)
2837 route_extended_t route = rc->get_route(rc,src,dst);
2840 double latency = 0.0;
2842 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
2843 latency += get_link_latency(link);
2848 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
2850 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
2853 static route_extended_t generic_get_bypassroute(routing_component_t rc,
2857 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2858 routing_component_t src_as, dst_as;
2859 int index_src, index_dst;
2860 xbt_dynar_t path_src = NULL;
2861 xbt_dynar_t path_dst = NULL;
2862 routing_component_t current = NULL;
2863 routing_component_t *current_src = NULL;
2864 routing_component_t *current_dst = NULL;
2866 /* (1) find the as where the src and dst are located */
2867 src_as = ((network_element_info_t)
2868 xbt_dict_get_or_null(global_routing->where_network_elements,
2869 src))->rc_component;
2870 dst_as = ((network_element_info_t)
2871 xbt_dict_get_or_null(global_routing->where_network_elements,
2872 dst))->rc_component;
2875 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
2878 /* (2) find the path to the root routing component */
2879 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
2881 while (current != NULL) {
2882 xbt_dynar_push(path_src, ¤t);
2883 current = current->routing_father;
2885 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
2887 while (current != NULL) {
2888 xbt_dynar_push(path_dst, ¤t);
2889 current = current->routing_father;
2892 /* (3) find the common father */
2893 index_src = path_src->used - 1;
2894 index_dst = path_dst->used - 1;
2895 current_src = xbt_dynar_get_ptr(path_src, index_src);
2896 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2897 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
2898 routing_component_t *tmp_src, *tmp_dst;
2899 tmp_src = xbt_dynar_pop_ptr(path_src);
2900 tmp_dst = xbt_dynar_pop_ptr(path_dst);
2903 current_src = xbt_dynar_get_ptr(path_src, index_src);
2904 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2907 int max_index_src = path_src->used - 1;
2908 int max_index_dst = path_dst->used - 1;
2910 int max_index = max(max_index_src, max_index_dst);
2913 route_extended_t e_route_bypass = NULL;
2915 for (max = 0; max <= max_index; max++) {
2916 for (i = 0; i < max; i++) {
2917 if (i <= max_index_src && max <= max_index_dst) {
2918 char *route_name = bprintf("%s#%s",
2919 (*(routing_component_t *)
2921 (path_src, i)))->name,
2922 (*(routing_component_t *)
2924 (path_dst, max)))->name);
2926 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2927 xbt_free(route_name);
2931 if (max <= max_index_src && i <= max_index_dst) {
2932 char *route_name = bprintf("%s#%s",
2933 (*(routing_component_t *)
2935 (path_src, max)))->name,
2936 (*(routing_component_t *)
2938 (path_dst, i)))->name);
2940 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2941 xbt_free(route_name);
2950 if (max <= max_index_src && max <= max_index_dst) {
2951 char *route_name = bprintf("%s#%s",
2952 (*(routing_component_t *)
2954 (path_src, max)))->name,
2955 (*(routing_component_t *)
2957 (path_dst, max)))->name);
2958 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2959 xbt_free(route_name);
2965 xbt_dynar_free(&path_src);
2966 xbt_dynar_free(&path_dst);
2968 route_extended_t new_e_route = NULL;
2970 if (e_route_bypass) {
2972 unsigned int cpt = 0;
2973 new_e_route = xbt_new0(s_route_extended_t, 1);
2974 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
2975 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
2976 new_e_route->generic_route.link_list =
2977 xbt_dynar_new(global_routing->size_of_link, NULL);
2978 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
2979 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
2986 /* ************************************************************************** */
2987 /* ************************* GENERIC AUX FUNCTIONS ************************** */
2990 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
2991 void *data, int order)
2997 xbt_dynar_t links = NULL, links_id = NULL;
2999 new_route = xbt_new0(s_route_t, 1);
3000 new_route->link_list =
3001 xbt_dynar_new(global_routing->size_of_link, NULL);
3003 xbt_assert0(hierarchy == SURF_ROUTING_BASE,
3004 "the hierarchy type is not SURF_ROUTING_BASE");
3006 links = ((route_t) data)->link_list;
3009 links_id = new_route->link_list;
3011 xbt_dynar_foreach(links, cpt, link_name) {
3014 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3017 xbt_dynar_push(links_id, &link);
3019 xbt_dynar_unshift(links_id, &link);
3021 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3027 static route_extended_t
3028 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
3029 void *data, int order)
3033 route_extended_t e_route, new_e_route;
3036 xbt_dynar_t links = NULL, links_id = NULL;
3038 new_e_route = xbt_new0(s_route_extended_t, 1);
3039 new_e_route->generic_route.link_list =
3040 xbt_dynar_new(global_routing->size_of_link, NULL);
3041 new_e_route->src_gateway = NULL;
3042 new_e_route->dst_gateway = NULL;
3044 xbt_assert0(hierarchy == SURF_ROUTING_BASE
3045 || hierarchy == SURF_ROUTING_RECURSIVE,
3046 "the hierarchy type is not defined");
3048 if (hierarchy == SURF_ROUTING_BASE) {
3050 route = (route_t) data;
3051 links = route->link_list;
3053 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
3055 e_route = (route_extended_t) data;
3056 xbt_assert0(e_route->src_gateway
3057 && e_route->dst_gateway, "bad gateway, is null");
3058 links = e_route->generic_route.link_list;
3060 /* remeber not erase the gateway names */
3061 new_e_route->src_gateway = e_route->src_gateway;
3062 new_e_route->dst_gateway = e_route->dst_gateway;
3065 links_id = new_e_route->generic_route.link_list;
3067 xbt_dynar_foreach(links, cpt, link_name) {
3070 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3073 xbt_dynar_push(links_id, &link);
3075 xbt_dynar_unshift(links_id, &link);
3077 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3083 static void generic_free_route(route_t route)
3086 xbt_dynar_free(&(route->link_list));
3091 static void generic_free_extended_route(route_extended_t e_route)
3094 xbt_dynar_free(&(e_route->generic_route.link_list));
3095 if (e_route->src_gateway)
3096 xbt_free(e_route->src_gateway);
3097 if (e_route->dst_gateway)
3098 xbt_free(e_route->dst_gateway);
3103 static routing_component_t generic_as_exist(routing_component_t find_from,
3104 routing_component_t to_find)
3106 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3107 xbt_dict_cursor_t cursor = NULL;
3110 routing_component_t elem;
3111 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
3112 if (to_find == elem || generic_as_exist(elem, to_find)) {
3122 static routing_component_t
3123 generic_autonomous_system_exist(routing_component_t rc, char *element)
3125 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3126 routing_component_t element_as, result, elem;
3127 xbt_dict_cursor_t cursor = NULL;
3129 element_as = ((network_element_info_t)
3130 xbt_dict_get_or_null
3131 (global_routing->where_network_elements,
3132 element))->rc_component;
3133 result = ((routing_component_t) - 1);
3134 if (element_as != rc)
3135 result = generic_as_exist(rc, element_as);
3139 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
3140 found = !strcmp(elem->name, element);
3150 static routing_component_t
3151 generic_processing_units_exist(routing_component_t rc, char *element)
3153 routing_component_t element_as;
3154 element_as = ((network_element_info_t)
3155 xbt_dict_get_or_null
3156 (global_routing->where_network_elements,
3157 element))->rc_component;
3158 if (element_as == rc)
3160 return generic_as_exist(rc, element_as);
3163 static void generic_src_dst_check(routing_component_t rc, const char *src,
3167 routing_component_t src_as = ((network_element_info_t)
3168 xbt_dict_get_or_null
3169 (global_routing->where_network_elements,
3170 src))->rc_component;
3171 routing_component_t dst_as = ((network_element_info_t)
3172 xbt_dict_get_or_null
3173 (global_routing->where_network_elements,
3174 dst))->rc_component;
3176 xbt_assert3(src_as != NULL && dst_as != NULL,
3177 "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
3178 src, dst, rc->name);
3179 xbt_assert4(src_as == dst_as,
3180 "The src(%s in %s) and dst(%s in %s) are in differents AS",
3181 src, src_as->name, dst, dst_as->name);
3182 xbt_assert2(rc == dst_as,
3183 "The routing component of src and dst is not the same as the network elements belong (%s==%s)",
3184 rc->name, dst_as->name);
3187 static void routing_parse_Sconfig(void)
3190 DEBUG0("WARNING tag config not yet implemented.");
3191 DEBUG1("Configuration name = %s",A_surfxml_config_id);
3194 static void routing_parse_Econfig(void)
3197 xbt_dict_cursor_t cursor = NULL;
3200 xbt_dict_foreach(current_property_set, cursor, key, elem) {
3201 DEBUG2("property : %s = %s",key,elem);
3205 static void routing_parse_Scluster(void)
3207 static int AX_ptr = 0;
3209 char *cluster_id = A_surfxml_cluster_id;
3210 char *cluster_prefix = A_surfxml_cluster_prefix;
3211 char *cluster_suffix = A_surfxml_cluster_suffix;
3212 char *cluster_radical = A_surfxml_cluster_radical;
3213 char *cluster_power = A_surfxml_cluster_power;
3214 char *cluster_bw = A_surfxml_cluster_bw;
3215 char *cluster_lat = A_surfxml_cluster_lat;
3216 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
3217 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
3218 char *host_id, *groups, *link_id = NULL;
3219 char *router_id, *link_router, *link_backbone;
3220 #ifdef HAVE_PCRE_LIB
3221 char *route_src_dst;
3225 xbt_dynar_t radical_elements;
3226 xbt_dynar_t radical_ends;
3227 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
3228 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
3230 #ifndef HAVE_PCRE_LIB
3231 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3232 char *route_src, *route_dst;
3236 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3237 static unsigned int surfxml_buffer_stack_stack[1024];
3239 surfxml_buffer_stack_stack[0] = 0;
3241 surfxml_bufferstack_push(1);
3243 SURFXML_BUFFER_SET(AS_id, cluster_id);
3244 #ifdef HAVE_PCRE_LIB
3245 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3246 DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
3248 SURFXML_BUFFER_SET(AS_routing, "Full");
3249 DEBUG1("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
3251 SURFXML_START_TAG(AS);
3253 radical_elements = xbt_str_split(cluster_radical, ",");
3254 xbt_dynar_foreach(radical_elements, iter, groups) {
3255 radical_ends = xbt_str_split(groups, "-");
3256 switch (xbt_dynar_length(radical_ends)) {
3258 surf_parse_get_int(&start,
3259 xbt_dynar_get_as(radical_ends, 0, char *));
3260 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
3261 #ifndef HAVE_PCRE_LIB
3262 xbt_dynar_push_as(tab_elements_num, int, start);
3264 link_id = bprintf("%s_link_%d", cluster_id, start);
3266 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, cluster_power);
3267 A_surfxml_host_state = A_surfxml_host_state_ON;
3268 SURFXML_BUFFER_SET(host_id, host_id);
3269 SURFXML_BUFFER_SET(host_power, cluster_power);
3270 SURFXML_BUFFER_SET(host_availability, "1.0");
3271 SURFXML_BUFFER_SET(host_availability_file, "");
3272 SURFXML_BUFFER_SET(host_state_file, "");
3273 SURFXML_START_TAG(host);
3274 SURFXML_END_TAG(host);
3276 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3277 A_surfxml_link_state = A_surfxml_link_state_ON;
3278 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3279 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3280 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3281 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3282 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3283 SURFXML_BUFFER_SET(link_id, link_id);
3284 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3285 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3286 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3287 SURFXML_BUFFER_SET(link_latency_file, "");
3288 SURFXML_BUFFER_SET(link_state_file, "");
3289 SURFXML_START_TAG(link);
3290 SURFXML_END_TAG(link);
3298 surf_parse_get_int(&start,
3299 xbt_dynar_get_as(radical_ends, 0, char *));
3300 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3301 DEBUG2("Create hosts and links from %d to %d", start, end);
3302 for (i = start; i <= end; i++) {
3303 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
3304 #ifndef HAVE_PCRE_LIB
3305 xbt_dynar_push_as(tab_elements_num, int, i);
3307 link_id = bprintf("%s_link_%d", cluster_id, i);
3309 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, cluster_power);
3310 A_surfxml_host_state = A_surfxml_host_state_ON;
3311 SURFXML_BUFFER_SET(host_id, host_id);
3312 SURFXML_BUFFER_SET(host_power, cluster_power);
3313 SURFXML_BUFFER_SET(host_availability, "1.0");
3314 SURFXML_BUFFER_SET(host_availability_file, "");
3315 SURFXML_BUFFER_SET(host_state_file, "");
3316 SURFXML_START_TAG(host);
3317 SURFXML_END_TAG(host);
3319 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3320 A_surfxml_link_state = A_surfxml_link_state_ON;
3321 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3322 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3323 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3324 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3325 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3326 SURFXML_BUFFER_SET(link_id, link_id);
3327 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3328 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3329 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3330 SURFXML_BUFFER_SET(link_latency_file, "");
3331 SURFXML_BUFFER_SET(link_state_file, "");
3332 SURFXML_START_TAG(link);
3333 SURFXML_END_TAG(link);
3341 DEBUG0("Malformed radical");
3344 xbt_dynar_free(&radical_ends);
3346 xbt_dynar_free(&radical_elements);
3350 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
3352 link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
3353 link_backbone = bprintf("%s_backbone", cluster_id);
3355 DEBUG1("<router id=\"%s\"/>", router_id);
3356 SURFXML_BUFFER_SET(router_id, router_id);;
3357 SURFXML_START_TAG(router);
3358 SURFXML_END_TAG(router);
3360 DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,cluster_bw, cluster_lat);
3361 A_surfxml_link_state = A_surfxml_link_state_ON;
3362 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3363 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3364 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3365 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3366 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3367 SURFXML_BUFFER_SET(link_id, link_router);
3368 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3369 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3370 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3371 SURFXML_BUFFER_SET(link_latency_file, "");
3372 SURFXML_BUFFER_SET(link_state_file, "");
3373 SURFXML_START_TAG(link);
3374 SURFXML_END_TAG(link);
3376 DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bw, cluster_lat);
3377 A_surfxml_link_state = A_surfxml_link_state_ON;
3378 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3379 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
3380 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3381 SURFXML_BUFFER_SET(link_id, link_backbone);
3382 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
3383 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
3384 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3385 SURFXML_BUFFER_SET(link_latency_file, "");
3386 SURFXML_BUFFER_SET(link_state_file, "");
3387 SURFXML_START_TAG(link);
3388 SURFXML_END_TAG(link);
3392 #ifdef HAVE_PCRE_LIB
3393 char *new_suffix = xbt_strdup("");
3395 radical_elements = xbt_str_split(cluster_suffix, ".");
3396 xbt_dynar_foreach(radical_elements, iter, groups) {
3397 if (strcmp(groups, "")) {
3398 char *old_suffix = new_suffix;
3399 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
3403 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
3404 xbt_dynar_free(&radical_elements);
3407 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
3408 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
3409 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
3411 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
3412 DEBUG0("symmetrical=\"NO\">");
3413 SURFXML_BUFFER_SET(route_src, route_src_dst);
3414 SURFXML_BUFFER_SET(route_dst, route_src_dst);
3415 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3416 SURFXML_START_TAG(route);
3418 DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_src);
3419 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
3420 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3421 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3422 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3423 SURFXML_START_TAG(link_ctn);
3424 SURFXML_END_TAG(link_ctn);
3426 DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
3427 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
3428 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3429 SURFXML_START_TAG(link_ctn);
3430 SURFXML_END_TAG(link_ctn);
3432 DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
3433 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
3434 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3435 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3436 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3437 SURFXML_START_TAG(link_ctn);
3438 SURFXML_END_TAG(link_ctn);
3441 SURFXML_END_TAG(route);
3443 free(pcre_link_dst);
3444 free(pcre_link_backbone);
3445 free(pcre_link_src);
3446 free(route_src_dst);
3448 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
3449 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
3450 if (i == xbt_dynar_length(tab_elements_num)) {
3451 route_src = router_id;
3454 bprintf("%s%d%s", cluster_prefix,
3455 xbt_dynar_get_as(tab_elements_num, i, int),
3459 if (j == xbt_dynar_length(tab_elements_num)) {
3460 route_dst = router_id;
3463 bprintf("%s%d%s", cluster_prefix,
3464 xbt_dynar_get_as(tab_elements_num, j, int),
3468 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
3469 DEBUG0("symmetrical=\"NO\">");
3470 SURFXML_BUFFER_SET(route_src, route_src);
3471 SURFXML_BUFFER_SET(route_dst, route_dst);
3472 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3473 SURFXML_START_TAG(route);
3475 if (i == xbt_dynar_length(tab_elements_num)) {
3476 route_src = link_router;
3479 bprintf("%s_link_%d", cluster_id,
3480 xbt_dynar_get_as(tab_elements_num, i, int));
3483 if (j == xbt_dynar_length(tab_elements_num)) {
3484 route_dst = link_router;
3487 bprintf("%s_link_%d", cluster_id,
3488 xbt_dynar_get_as(tab_elements_num, j, int));
3491 DEBUG1("<link_ctn\tid=\"%s\"/>", route_src);
3492 SURFXML_BUFFER_SET(link_ctn_id, route_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_backbone\"/>", cluster_id);
3500 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
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\"/>", route_dst);
3506 SURFXML_BUFFER_SET(link_ctn_id, route_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);
3517 xbt_dynar_free(&tab_elements_num);
3522 free(link_backbone);
3526 SURFXML_END_TAG(AS);
3529 surfxml_bufferstack_pop(1);
3533 * New methods to init the routing model component from the lua script
3537 * calling parse_S_AS_lua with lua values
3539 void routing_AS_init(const char *AS_id, const char *AS_routing)
3541 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
3545 * calling parse_E_AS_lua to fisnish the creation of routing component
3547 void routing_AS_end(const char *AS_id)
3549 parse_E_AS_lua((char *) AS_id);
3553 * add a host to the network element list
3556 void routing_add_host(const char *host_id)
3558 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
3562 * Set a new link on the actual list of link for a route or ASroute
3564 void routing_add_link(const char *link_id)
3566 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
3570 *Set the endpoints for a route
3572 void routing_set_route(const char *src_id, const char *dst_id)
3574 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
3578 * Store the route by calling parse_E_route_store_route
3580 void routing_store_route(void)
3582 parse_E_route_store_route();