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_pvoid_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 * \brief Add a "host" to the network element list
163 static void parse_S_host(char *host_id)
165 network_element_info_t info = NULL;
166 if (current_routing->hierarchy == SURF_ROUTING_NULL)
167 current_routing->hierarchy = SURF_ROUTING_BASE;
168 xbt_assert1(!xbt_dict_get_or_null
169 (global_routing->where_network_elements, host_id),
170 "Reading a host, processing unit \"%s\" already exists",
172 xbt_assert1(current_routing->set_processing_unit,
173 "no defined method \"set_processing_unit\" in \"%s\"",
174 current_routing->name);
175 (*(current_routing->set_processing_unit)) (current_routing, host_id);
176 info = xbt_new0(s_network_element_info_t, 1);
177 info->rc_component = current_routing;
178 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
179 xbt_dict_set(global_routing->where_network_elements, host_id,
180 (void *) info, NULL);
184 * \brief Add a host to the network element list from XML
186 static void parse_S_host_XML(void)
188 parse_S_host(A_surfxml_host_id);
192 * \brief Add a host to the network element list from lua script
194 static void parse_S_host_lua(char *host_id)
196 parse_S_host(host_id);
201 * \brief Add a "router" to the network element list
203 static void parse_S_router(void)
205 network_element_info_t info = NULL;
207 if (current_routing->hierarchy == SURF_ROUTING_NULL)
208 current_routing->hierarchy = SURF_ROUTING_BASE;
209 xbt_assert1(!xbt_dict_get_or_null
210 (global_routing->where_network_elements,
211 A_surfxml_router_id),
212 "Reading a router, processing unit \"%s\" already exists",
213 A_surfxml_router_id);
214 xbt_assert1(current_routing->set_processing_unit,
215 "no defined method \"set_processing_unit\" in \"%s\"",
216 current_routing->name);
217 (*(current_routing->set_processing_unit)) (current_routing,
218 A_surfxml_router_id);
219 info = xbt_new0(s_network_element_info_t, 1);
220 info->rc_component = current_routing;
221 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
222 xbt_dict_set(global_routing->where_network_elements, A_surfxml_router_id,
223 (void *) info, NULL);
225 TRACE_surf_host_declaration(A_surfxml_router_id, 0);
230 * \brief Set the endponints for a route
232 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
234 if (src != NULL && dst != NULL && link_list != NULL)
235 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
239 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0,
240 "Some limits are null in the route between \"%s\" and \"%s\"",
242 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
246 * \breif Set the endpoints for a route from XML
248 static void parse_S_route_new_and_endpoints_XML(void)
250 parse_S_route_new_and_endpoints(A_surfxml_route_src,
251 A_surfxml_route_dst);
255 * \breif Set the endpoints for a route from lua
257 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
259 parse_S_route_new_and_endpoints(id_src, id_dst);
263 * \brief Set the endponints and gateways for a ASroute
265 static void parse_S_ASroute_new_and_endpoints(void)
267 if (src != NULL && dst != NULL && link_list != NULL)
268 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
269 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
270 src = A_surfxml_ASroute_src;
271 dst = A_surfxml_ASroute_dst;
272 gw_src = A_surfxml_ASroute_gw_src;
273 gw_dst = A_surfxml_ASroute_gw_dst;
274 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
275 || strlen(gw_dst) > 0,
276 "Some limits are null in the route between \"%s\" and \"%s\"",
278 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
282 * \brief Set the endponints for a bypassRoute
284 static void parse_S_bypassRoute_new_and_endpoints(void)
286 if (src != NULL && dst != NULL && link_list != NULL)
288 "Bypass Route between %s to %s can not be defined",
289 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
290 src = A_surfxml_bypassRoute_src;
291 dst = A_surfxml_bypassRoute_dst;
292 gw_src = A_surfxml_bypassRoute_gw_src;
293 gw_dst = A_surfxml_bypassRoute_gw_dst;
294 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
295 || strlen(gw_dst) > 0,
296 "Some limits are null in the route between \"%s\" and \"%s\"",
298 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
302 * \brief Set a new link on the actual list of link for a route or ASroute
304 static void parse_E_link_ctn_new_elem(char *link_id)
307 val = xbt_strdup(link_id);
308 xbt_dynar_push(link_list, &val);
312 * \brief Set a new link on the actual list of link for a route or ASroute from XML
315 static void parse_E_link_ctn_new_elem_XML(void)
317 if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
318 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
319 if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP)
320 parse_E_link_ctn_new_elem(bprintf("%s_UP",A_surfxml_link_ctn_id));
321 if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN)
322 parse_E_link_ctn_new_elem(bprintf("%s_DOWN",A_surfxml_link_ctn_id));
326 * \brief Set a new link on the actual list of link for a route or ASroute from lua
328 static void parse_E_link_c_ctn_new_elem_lua(char *link_id)
330 parse_E_link_ctn_new_elem(link_id);
334 * \brief Store the route by calling the set_route function of the current routing component
336 static void parse_E_route_store_route(void)
338 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
339 route->generic_route.link_list = link_list;
340 xbt_assert1(current_routing->set_route,
341 "no defined method \"set_route\" in \"%s\"",
342 current_routing->name);
343 (*(current_routing->set_route)) (current_routing, src, dst, route);
350 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
352 static void parse_E_ASroute_store_route(void)
354 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
355 e_route->generic_route.link_list = link_list;
356 e_route->src_gateway = xbt_strdup(gw_src);
357 e_route->dst_gateway = xbt_strdup(gw_dst);
358 xbt_assert1(current_routing->set_ASroute,
359 "no defined method \"set_ASroute\" in \"%s\"",
360 current_routing->name);
361 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
370 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
372 static void parse_E_bypassRoute_store_route(void)
374 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
375 e_route->generic_route.link_list = link_list;
376 e_route->src_gateway = xbt_strdup(gw_src);
377 e_route->dst_gateway = xbt_strdup(gw_dst);
378 xbt_assert1(current_routing->set_bypassroute,
379 "no defined method \"set_bypassroute\" in \"%s\"",
380 current_routing->name);
381 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
391 * \brief Make a new routing component
393 * make the new structure and
394 * set the parsing functions to allows parsing the part of the routing tree
396 static void parse_S_AS(char *AS_id, char *AS_routing)
398 routing_component_t new_routing;
399 model_type_t model = NULL;
400 char *wanted = AS_routing;
402 /* seach the routing model */
403 for (cpt = 0; routing_models[cpt].name; cpt++)
404 if (!strcmp(wanted, routing_models[cpt].name))
405 model = &routing_models[cpt];
406 /* if its not exist, error */
408 fprintf(stderr, "Routing model %s not found. Existing models:\n",
410 for (cpt = 0; routing_models[cpt].name; cpt++)
411 if (!strcmp(wanted, routing_models[cpt].name))
412 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
413 routing_models[cpt].desc);
417 /* make a new routing component */
418 new_routing = (routing_component_t) (*(model->create)) ();
419 new_routing->routing = model;
420 new_routing->hierarchy = SURF_ROUTING_NULL;
421 new_routing->name = xbt_strdup(AS_id);
422 new_routing->routing_sons = xbt_dict_new();
424 if (current_routing == NULL && global_routing->root == NULL) {
426 /* it is the first one */
427 new_routing->routing_father = NULL;
428 global_routing->root = new_routing;
430 } else if (current_routing != NULL && global_routing->root != NULL) {
432 xbt_assert1(!xbt_dict_get_or_null
433 (current_routing->routing_sons, AS_id),
434 "The AS \"%s\" already exists", AS_id);
435 /* it is a part of the tree */
436 new_routing->routing_father = current_routing;
437 /* set the father behavior */
438 if (current_routing->hierarchy == SURF_ROUTING_NULL)
439 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
440 /* add to the sons dictionary */
441 xbt_dict_set(current_routing->routing_sons, AS_id,
442 (void *) new_routing, NULL);
443 /* add to the father element list */
444 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
445 /* unload the prev parse rules */
446 (*(current_routing->routing->unload)) ();
449 THROW0(arg_error, 0, "All defined components must be belong to a AS");
451 /* set the new parse rules */
452 (*(new_routing->routing->load)) ();
453 /* set the new current component of the tree */
454 current_routing = new_routing;
458 * Detect the routing model type of the routing component from XML platforms
460 static void parse_S_AS_XML(void)
462 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
466 * define the routing model type of routing component from lua script
468 static void parse_S_AS_lua(char *id, char *mode)
470 parse_S_AS(id, mode);
475 * \brief Finish the creation of a new routing component
477 * When you finish to read the routing component, other structures must be created.
478 * the "end" method allow to do that for any routing model type
480 static void parse_E_AS(char *AS_id)
483 if (current_routing == NULL) {
484 THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id);
486 network_element_info_t info = NULL;
487 xbt_assert1(!xbt_dict_get_or_null
488 (global_routing->where_network_elements,
489 current_routing->name), "The AS \"%s\" already exists",
490 current_routing->name);
491 info = xbt_new0(s_network_element_info_t, 1);
492 info->rc_component = current_routing->routing_father;
493 info->rc_type = SURF_NETWORK_ELEMENT_AS;
494 xbt_dict_set(global_routing->where_network_elements,
495 current_routing->name, info, NULL);
496 (*(current_routing->routing->unload)) ();
497 (*(current_routing->routing->end)) ();
498 current_routing = current_routing->routing_father;
499 if (current_routing != NULL)
500 (*(current_routing->routing->load)) ();
505 * \brief Finish the creation of a new routing component from XML
507 static void parse_E_AS_XML(void)
509 parse_E_AS(A_surfxml_AS_id);
513 * \brief Finish the creation of a new routing component from lua
515 static void parse_E_AS_lua(char *id)
520 /* Aux Business methods */
523 * \brief Get the AS father and the first elements of the chain
525 * \param src the source host name
526 * \param dst the destination host name
528 * Get the common father of the to processing units, and the first different
529 * father in the chain
531 static xbt_dynar_t elements_father(const char *src, const char *dst)
534 xbt_assert0(src && dst, "bad parameters for \"elements_father\" method");
536 xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
538 routing_component_t src_as, dst_as;
539 int index_src, index_dst, index_father_src, index_father_dst;
540 xbt_dynar_t path_src = NULL;
541 xbt_dynar_t path_dst = NULL;
542 routing_component_t current = NULL;
543 routing_component_t *current_src = NULL;
544 routing_component_t *current_dst = NULL;
545 routing_component_t *father = NULL;
547 /* (1) find the as where the src and dst are located */
548 src_as = ((network_element_info_t)
549 xbt_dict_get_or_null(global_routing->where_network_elements,
551 dst_as = ((network_element_info_t)
552 xbt_dict_get_or_null(global_routing->where_network_elements,
556 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
559 /* (2) find the path to the root routing component */
560 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
562 while (current != NULL) {
563 xbt_dynar_push(path_src, ¤t);
564 current = current->routing_father;
566 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
568 while (current != NULL) {
569 xbt_dynar_push(path_dst, ¤t);
570 current = current->routing_father;
573 /* (3) find the common father */
574 index_src = (path_src->used) - 1;
575 index_dst = (path_dst->used) - 1;
576 current_src = xbt_dynar_get_ptr(path_src, index_src);
577 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
578 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
579 current_src = xbt_dynar_get_ptr(path_src, index_src);
580 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
586 current_src = xbt_dynar_get_ptr(path_src, index_src);
587 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
589 /* (4) they are not in the same routing component, make the path */
590 index_father_src = index_src + 1;
591 index_father_dst = index_dst + 1;
593 if (*current_src == *current_dst)
594 father = current_src;
596 father = xbt_dynar_get_ptr(path_src, index_father_src);
598 /* (5) result generation */
599 xbt_dynar_push(result, father); /* first same the father of src and dst */
600 xbt_dynar_push(result, current_src); /* second the first different father of src */
601 xbt_dynar_push(result, current_dst); /* three the first different father of dst */
603 xbt_dynar_free(&path_src);
604 xbt_dynar_free(&path_dst);
609 /* Global Business methods */
612 * \brief Recursive function for get_route
614 * \param src the source host name
615 * \param dst the destination host name
617 * This fuction is call by "get_route". It allow to walk through the
618 * routing components tree.
620 static route_extended_t _get_route(const char *src, const char *dst)
624 unsigned int cpt = 0;
626 DEBUG2("Solve route \"%s\" to \"%s\"", src, dst);
628 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
630 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
633 xbt_dynar_t elem_father_list = elements_father(src, dst);
635 routing_component_t common_father =
636 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
637 routing_component_t src_father =
638 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
639 routing_component_t dst_father =
640 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
642 e_route = xbt_new0(s_route_extended_t, 1);
643 e_route->src_gateway = NULL;
644 e_route->dst_gateway = NULL;
645 e_route->generic_route.link_list =
646 xbt_dynar_new(global_routing->size_of_link, NULL);
648 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
650 if (strcmp(src, dst)) {
652 (*(common_father->get_route)) (common_father, src, dst);
653 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
655 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
656 xbt_dynar_push(e_route->generic_route.link_list, &link);
658 generic_free_extended_route(e_route_cnt);
661 } else { /* SURF_ROUTING_RECURSIVE */
663 route_extended_t e_route_bypass = NULL;
665 if (common_father->get_bypass_route)
667 (*(common_father->get_bypass_route)) (common_father, src, dst);
670 e_route_cnt = e_route_bypass;
673 (*(common_father->get_route)) (common_father, src_father->name,
676 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
677 src_father->name, dst_father->name);
679 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
680 (e_route_cnt->dst_gateway == NULL),
681 "bad gateway for route between \"%s\" and \"%s\"", src,
684 if (src != e_route_cnt->src_gateway) {
685 e_route_src = _get_route(src, e_route_cnt->src_gateway);
686 xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
687 e_route_cnt->src_gateway);
688 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
689 xbt_dynar_push(e_route->generic_route.link_list, &link);
693 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
694 xbt_dynar_push(e_route->generic_route.link_list, &link);
697 if (e_route_cnt->dst_gateway != dst) {
698 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
699 xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
700 e_route_cnt->dst_gateway, dst);
701 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
702 xbt_dynar_push(e_route->generic_route.link_list, &link);
706 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
707 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
709 generic_free_extended_route(e_route_src);
710 generic_free_extended_route(e_route_cnt);
711 generic_free_extended_route(e_route_dst);
714 xbt_dynar_free(&elem_father_list);
719 static double _get_latency(const char *src, const char *dst)
723 unsigned int cpt = 0;
724 double latency, latency_src, latency_dst = 0.0;
726 DEBUG2("Solve route \"%s\" to \"%s\"", src, dst);
728 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
730 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
733 xbt_dynar_t elem_father_list = elements_father(src, dst);
735 routing_component_t common_father =
736 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
737 routing_component_t src_father =
738 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
739 routing_component_t dst_father =
740 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
742 e_route = xbt_new0(s_route_extended_t, 1);
743 e_route->src_gateway = NULL;
744 e_route->dst_gateway = NULL;
745 e_route->generic_route.link_list =
746 xbt_dynar_new(global_routing->size_of_link, NULL);
748 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
750 if (strcmp(src, dst)) {
752 (*(common_father->get_latency)) (common_father, src, dst);
753 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"", src,
756 } else { /* SURF_ROUTING_RECURSIVE */
757 route_extended_t e_route_bypass = NULL;
759 if (common_father->get_bypass_route)
761 (*(common_father->get_bypass_route)) (common_father, src, dst);
763 xbt_assert0(!e_route_bypass,"Bypass cannot work yet with get_latency");
766 (*(common_father->get_route)) (common_father, src_father->name,
769 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
770 src_father->name, dst_father->name);
772 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
773 (e_route_cnt->dst_gateway == NULL),
774 "bad gateway for route between \"%s\" and \"%s\"", src,
777 (*(common_father->get_latency)) (common_father, src_father->name,
779 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"",
780 src_father->name, dst_father->name);
783 if (src != e_route_cnt->src_gateway) {
785 e_route_src = _get_route(src, e_route_cnt->src_gateway);
786 xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
787 e_route_cnt->src_gateway);
788 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
789 xbt_dynar_push(e_route->generic_route.link_list, &link);
792 latency_src = _get_latency(src, e_route_cnt->src_gateway);
793 xbt_assert2(latency_src>=0, "no route between \"%s\" and \"%s\"", src,
794 e_route_cnt->src_gateway);
795 latency += latency_src;
799 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
800 xbt_dynar_push(e_route->generic_route.link_list, &link);
804 if (e_route_cnt->dst_gateway != dst) {
806 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
807 xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
808 e_route_cnt->dst_gateway, dst);
809 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
810 xbt_dynar_push(e_route->generic_route.link_list, &link);
813 latency_dst = _get_latency(e_route_cnt->dst_gateway, dst);
814 xbt_assert2(latency_dst>=0, "no route between \"%s\" and \"%s\"",
815 e_route_cnt->dst_gateway, dst);
816 latency += latency_dst;
820 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
821 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
823 generic_free_extended_route(e_route_src);
824 generic_free_extended_route(e_route_cnt);
825 generic_free_extended_route(e_route_dst);
829 xbt_dynar_free(&elem_father_list);
835 * \brief Generic method: find a route between hosts
837 * \param src the source host name
838 * \param dst the destination host name
840 * walk through the routing components tree and find a route between hosts
841 * by calling the differents "get_route" functions in each routing component.
842 * No need to free the returned dynar. It will be freed at the next call.
844 static xbt_dynar_t get_route(const char *src, const char *dst)
847 route_extended_t e_route;
848 xbt_dynar_t elem_father_list = elements_father(src, dst);
849 routing_component_t common_father =
850 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
852 if (strcmp(src, dst))
853 e_route = _get_route(src, dst);
855 e_route = (*(common_father->get_route)) (common_father, src, dst);
857 xbt_assert2(e_route, "no route between \"%s\" and \"%s\"", src, dst);
859 if (global_routing->last_route)
860 xbt_dynar_free(&(global_routing->last_route));
861 global_routing->last_route = e_route->generic_route.link_list;
863 if (e_route->src_gateway)
864 xbt_free(e_route->src_gateway);
865 if (e_route->dst_gateway)
866 xbt_free(e_route->dst_gateway);
869 xbt_dynar_free(&elem_father_list);
871 if (xbt_dynar_length(global_routing->last_route) == 0)
874 return global_routing->last_route;
878 * \brief Generic method: find a route between hosts
880 * \param src the source host name
881 * \param dst the destination host name
883 * walk through the routing components tree and find a route between hosts
884 * by calling the differents "get_route" functions in each routing component.
885 * Leaves the caller the responsability to clean the returned dynar.
887 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
889 xbt_dynar_t d = get_route(src,dst);
890 global_routing->last_route = NULL;
895 static double get_latency(const char *src, const char *dst)
898 double latency = -1.0;
899 xbt_dynar_t elem_father_list = elements_father(src, dst);
900 routing_component_t common_father =
901 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
903 if (strcmp(src, dst))
904 latency = _get_latency(src, dst);
906 latency = (*(common_father->get_latency)) (common_father, src, dst);
908 xbt_assert2(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst);
914 * \brief Recursive function for finalize
916 * \param rc the source host name
918 * This fuction is call by "finalize". It allow to finalize the
919 * AS or routing components. It delete all the structures.
921 static void _finalize(routing_component_t rc)
924 xbt_dict_cursor_t cursor = NULL;
926 routing_component_t elem;
927 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
930 xbt_dict_t tmp_sons = rc->routing_sons;
931 char *tmp_name = rc->name;
932 xbt_dict_free(&tmp_sons);
934 xbt_assert1(rc->finalize, "no defined method \"finalize\" in \"%s\"",
935 current_routing->name);
936 (*(rc->finalize)) (rc);
941 * \brief Generic method: delete all the routing structures
943 * walk through the routing components tree and delete the structures
944 * by calling the differents "finalize" functions in each routing component
946 static void finalize(void)
948 /* delete recursibly all the tree */
949 _finalize(global_routing->root);
950 /* delete "where" dict */
951 xbt_dict_free(&(global_routing->where_network_elements));
952 /* delete last_route */
953 xbt_dynar_free(&(global_routing->last_route));
954 /* delete global routing structure */
955 xbt_free(global_routing);
958 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
960 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
962 //adding my one link routes
965 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
967 xbt_dynar_foreach(onelink_mine, cpt, link) {
968 xbt_dynar_push(ret, &link);
973 xbt_dict_cursor_t cursor = NULL;
974 routing_component_t rc_child;
975 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
976 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
978 xbt_dynar_foreach(onelink_child, cpt, link) {
979 xbt_dynar_push(ret, &link);
986 static xbt_dynar_t get_onelink_routes(void)
988 return recursive_get_onelink_routes(global_routing->root);
991 static e_surf_network_element_type_t get_network_element_type(const char
994 network_element_info_t rc = NULL;
995 rc = xbt_dict_get(global_routing->where_network_elements, name);
1000 * \brief Generic method: create the global routing schema
1002 * Make a global routing structure and set all the parsing functions.
1004 void routing_model_create(size_t size_of_links, void *loopback, double_f_pvoid_t get_link_latency_fun )
1007 /* config the uniq global routing */
1008 global_routing = xbt_new0(s_routing_global_t, 1);
1009 global_routing->where_network_elements = xbt_dict_new();
1010 global_routing->root = NULL;
1011 global_routing->get_route = get_route;
1012 global_routing->get_latency = get_latency;
1013 global_routing->get_route_no_cleanup = get_route_no_cleanup;
1014 global_routing->get_onelink_routes = get_onelink_routes;
1015 global_routing->get_network_element_type = get_network_element_type;
1016 global_routing->finalize = finalize;
1017 global_routing->loopback = loopback;
1018 global_routing->size_of_link = size_of_links;
1019 global_routing->last_route = NULL;
1020 get_link_latency = get_link_latency_fun;
1021 /* no current routing at moment */
1022 current_routing = NULL;
1024 /* parse generic elements */
1025 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
1026 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
1028 surfxml_add_callback(STag_surfxml_route_cb_list,
1029 &parse_S_route_new_and_endpoints_XML);
1030 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
1031 &parse_S_ASroute_new_and_endpoints);
1032 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
1033 &parse_S_bypassRoute_new_and_endpoints);
1035 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
1036 &parse_E_link_ctn_new_elem_XML);
1038 surfxml_add_callback(ETag_surfxml_route_cb_list,
1039 &parse_E_route_store_route);
1040 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
1041 &parse_E_ASroute_store_route);
1042 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
1043 &parse_E_bypassRoute_store_route);
1045 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
1046 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
1048 surfxml_add_callback(STag_surfxml_cluster_cb_list,
1049 &routing_parse_Scluster);
1051 surfxml_add_callback(STag_surfxml_config_cb_list,
1052 &routing_parse_Sconfig);
1053 surfxml_add_callback(ETag_surfxml_config_cb_list,
1054 &routing_parse_Econfig);
1057 /* ************************************************************************** */
1058 /* *************************** FULL ROUTING ********************************* */
1060 #define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
1062 /* Routing model structure */
1065 s_routing_component_t generic_routing;
1066 route_extended_t *routing_table;
1067 } s_routing_component_full_t, *routing_component_full_t;
1069 /* Business methods */
1070 static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
1072 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1074 routing_component_full_t routing = (routing_component_full_t) rc;
1075 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1076 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1077 char *k1, *d1, *k2, *d2;
1078 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1079 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1080 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k1);
1081 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k2);
1084 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1086 route_extended_t route = TO_ROUTE_FULL(*src_id, *dst_id);
1088 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1090 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1092 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1093 onelink->link_ptr = link;
1094 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1095 onelink->src = xbt_strdup(k1);
1096 onelink->dst = xbt_strdup(k2);
1097 } else if (routing->generic_routing.hierarchy ==
1098 SURF_ROUTING_RECURSIVE) {
1099 onelink->src = xbt_strdup(route->src_gateway);
1100 onelink->dst = xbt_strdup(route->dst_gateway);
1102 xbt_dynar_push(ret, &onelink);
1110 static route_extended_t full_get_route(routing_component_t rc,
1111 const char *src, const char *dst)
1113 xbt_assert1(rc && src
1115 "Invalid params for \"get_route\" function at AS \"%s\"",
1118 /* set utils vars */
1119 routing_component_full_t routing = (routing_component_full_t) rc;
1120 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1122 generic_src_dst_check(rc, src, dst);
1123 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1124 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1127 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1130 route_extended_t e_route = NULL;
1131 route_extended_t new_e_route = NULL;
1133 unsigned int cpt = 0;
1135 e_route = TO_ROUTE_FULL(*src_id, *dst_id);
1138 new_e_route = xbt_new0(s_route_extended_t, 1);
1139 new_e_route->src_gateway = xbt_strdup(e_route->src_gateway);
1140 new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway);
1141 new_e_route->generic_route.link_list =
1142 xbt_dynar_new(global_routing->size_of_link, NULL);
1143 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
1144 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1150 static void full_finalize(routing_component_t rc)
1152 routing_component_full_t routing = (routing_component_full_t) rc;
1153 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1156 /* Delete routing table */
1157 for (i = 0; i < table_size; i++)
1158 for (j = 0; j < table_size; j++)
1159 generic_free_extended_route(TO_ROUTE_FULL(i, j));
1160 xbt_free(routing->routing_table);
1161 /* Delete bypass dict */
1162 xbt_dict_free(&rc->bypassRoutes);
1163 /* Delete index dict */
1164 xbt_dict_free(&rc->to_index);
1165 /* Delete structure */
1170 /* Creation routing model functions */
1172 static void *model_full_create(void)
1174 routing_component_full_t new_component =
1175 xbt_new0(s_routing_component_full_t, 1);
1176 new_component->generic_routing.set_processing_unit =
1177 generic_set_processing_unit;
1178 new_component->generic_routing.set_autonomous_system =
1179 generic_set_autonomous_system;
1180 new_component->generic_routing.set_route = model_full_set_route;
1181 new_component->generic_routing.set_ASroute = model_full_set_route;
1182 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1183 new_component->generic_routing.get_route = full_get_route;
1184 new_component->generic_routing.get_latency = generic_get_link_latency;
1185 new_component->generic_routing.get_onelink_routes =
1186 full_get_onelink_routes;
1187 new_component->generic_routing.get_bypass_route =
1188 generic_get_bypassroute;
1189 new_component->generic_routing.finalize = full_finalize;
1190 new_component->generic_routing.to_index = xbt_dict_new();
1191 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1192 return new_component;
1195 static void model_full_load(void)
1197 /* use "surfxml_add_callback" to add a parse function call */
1200 static void model_full_unload(void)
1202 /* use "surfxml_del_callback" to remove a parse function call */
1205 static void model_full_end(void)
1208 route_extended_t e_route;
1210 /* set utils vars */
1211 routing_component_full_t routing =
1212 ((routing_component_full_t) current_routing);
1213 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1215 /* Create table if necessary */
1216 if(!routing->routing_table)
1217 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1219 /* Add the loopback if needed */
1220 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1221 for (i = 0; i < table_size; i++) {
1222 e_route = TO_ROUTE_FULL(i, i);
1224 e_route = xbt_new0(s_route_extended_t, 1);
1225 e_route->src_gateway = NULL;
1226 e_route->dst_gateway = NULL;
1227 e_route->generic_route.link_list =
1228 xbt_dynar_new(global_routing->size_of_link, NULL);
1229 xbt_dynar_push(e_route->generic_route.link_list,
1230 &global_routing->loopback);
1231 TO_ROUTE_FULL(i, i) = e_route;
1237 static void model_full_set_route(routing_component_t rc, const char *src,
1238 const char *dst, name_route_extended_t route)
1240 int *src_id, *dst_id;
1241 src_id = xbt_dict_get_or_null(rc->to_index, src);
1242 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1243 routing_component_full_t routing = ((routing_component_full_t) rc);
1244 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1247 && dst_id, "Network elements %s or %s not found", src, dst);
1249 xbt_assert2(xbt_dynar_length(route->generic_route.link_list) > 0,
1250 "Invalid count of links, must be greater than zero (%s,%s)",
1253 if(!routing->routing_table)
1254 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1256 if(TO_ROUTE_FULL(*src_id, *dst_id))
1260 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1261 xbt_dynar_foreach(route->generic_route.link_list,i,link_name)
1263 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1264 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1265 xbt_dynar_push(link_route_to_test,&link);
1267 xbt_assert2(!xbt_dynar_compare(
1268 (void*)TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list,
1269 (void*)link_route_to_test,
1270 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1271 "The route between \"%s\" and \"%s\" already exists", src,dst);
1272 xbt_free(link_route_to_test);
1276 if(!route->dst_gateway && !route->src_gateway)
1277 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1279 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1280 route->src_gateway, dst, route->dst_gateway);
1281 TO_ROUTE_FULL(*src_id, *dst_id) = generic_new_extended_route(rc->hierarchy,route,1);
1282 xbt_dynar_shrink(TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list, 0);
1285 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1286 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1288 if(route->dst_gateway && route->src_gateway)
1290 char * gw_src = bprintf("%s",route->src_gateway);
1291 char * gw_dst = bprintf("%s",route->dst_gateway);
1292 route->src_gateway = bprintf("%s",gw_dst);
1293 route->dst_gateway = bprintf("%s",gw_src);
1295 if(TO_ROUTE_FULL(*dst_id, *src_id))
1299 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1300 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1302 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1303 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1304 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1305 xbt_dynar_push(link_route_to_test,&link);
1307 xbt_assert2(!xbt_dynar_compare(
1308 (void*)TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list,
1309 (void*)link_route_to_test,
1310 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1311 "The route between \"%s\" and \"%s\" already exists", src,dst);
1312 xbt_free(link_route_to_test);
1316 if(!route->dst_gateway && !route->src_gateway)
1317 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1319 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1320 route->src_gateway, src, route->dst_gateway);
1321 TO_ROUTE_FULL(*dst_id, *src_id) = generic_new_extended_route(rc->hierarchy,route,0);
1322 xbt_dynar_shrink(TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list, 0);
1328 /* ************************************************************************** */
1329 /* *************************** FLOYD ROUTING ******************************** */
1331 #define TO_FLOYD_COST(i,j) (routing->cost_table)[(i)+(j)*table_size]
1332 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
1333 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
1335 /* Routing model structure */
1338 s_routing_component_t generic_routing;
1339 /* vars for calculate the floyd algorith. */
1340 int *predecessor_table;
1342 route_extended_t *link_table; /* char* -> int* */
1343 } s_routing_component_floyd_t, *routing_component_floyd_t;
1345 static route_extended_t floyd_get_route(routing_component_t rc,
1346 const char *src, const char *dst);
1348 /* Business methods */
1349 static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
1351 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1353 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1354 //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1355 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1356 char *k1, *d1, *k2, *d2;
1357 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1358 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1359 route_extended_t route = floyd_get_route(rc, k1, k2);
1361 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1363 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1365 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1366 onelink->link_ptr = link;
1367 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1368 onelink->src = xbt_strdup(k1);
1369 onelink->dst = xbt_strdup(k2);
1370 } else if (routing->generic_routing.hierarchy ==
1371 SURF_ROUTING_RECURSIVE) {
1372 onelink->src = xbt_strdup(route->src_gateway);
1373 onelink->dst = xbt_strdup(route->dst_gateway);
1375 xbt_dynar_push(ret, &onelink);
1383 static route_extended_t floyd_get_route(routing_component_t rc,
1384 const char *src, const char *dst)
1386 xbt_assert1(rc && src
1388 "Invalid params for \"get_route\" function at AS \"%s\"",
1391 /* set utils vars */
1392 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1393 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1395 generic_src_dst_check(rc, src, dst);
1396 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1397 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1400 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1403 /* create a result route */
1404 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1405 new_e_route->generic_route.link_list =
1406 xbt_dynar_new(global_routing->size_of_link, NULL);
1407 new_e_route->src_gateway = NULL;
1408 new_e_route->dst_gateway = NULL;
1413 char *gw_src = NULL, *gw_dst =
1414 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1421 pred = TO_FLOYD_PRED(*src_id, pred);
1422 if (pred == -1) /* if no pred in route -> no route to host */
1424 xbt_assert2(TO_FLOYD_LINK(pred, prev_pred),
1425 "Invalid link for the route between \"%s\" or \"%s\"", src,
1428 prev_gw_src = gw_src;
1429 prev_gw_dst = gw_dst;
1431 route_extended_t e_route = TO_FLOYD_LINK(pred, prev_pred);
1432 gw_src = e_route->src_gateway;
1433 gw_dst = e_route->dst_gateway;
1438 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && !first
1439 && strcmp(gw_dst, prev_gw_src)) {
1440 xbt_dynar_t e_route_as_to_as =
1441 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1442 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1443 gw_dst, prev_gw_src);
1444 links = e_route_as_to_as;
1446 xbt_dynar_foreach(links, cpt, link) {
1447 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1453 links = e_route->generic_route.link_list;
1454 xbt_dynar_foreach(links, cpt, link) {
1455 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1459 } while (pred != *src_id);
1460 xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")",
1461 *src_id, *dst_id, src, dst);
1463 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1464 new_e_route->src_gateway = xbt_strdup(gw_src);
1465 new_e_route->dst_gateway = xbt_strdup(first_gw);
1471 static void floyd_finalize(routing_component_t rc)
1473 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1477 table_size = xbt_dict_length(routing->generic_routing.to_index);
1478 /* Delete link_table */
1479 for (i = 0; i < table_size; i++)
1480 for (j = 0; j < table_size; j++)
1481 generic_free_extended_route(TO_FLOYD_LINK(i, j));
1482 xbt_free(routing->link_table);
1483 /* Delete bypass dict */
1484 xbt_dict_free(&routing->generic_routing.bypassRoutes);
1485 /* Delete index dict */
1486 xbt_dict_free(&(routing->generic_routing.to_index));
1487 /* Delete dictionary index dict, predecessor and links table */
1488 xbt_free(routing->predecessor_table);
1489 /* Delete structure */
1494 static void *model_floyd_create(void)
1496 routing_component_floyd_t new_component =
1497 xbt_new0(s_routing_component_floyd_t, 1);
1498 new_component->generic_routing.set_processing_unit =
1499 generic_set_processing_unit;
1500 new_component->generic_routing.set_autonomous_system =
1501 generic_set_autonomous_system;
1502 new_component->generic_routing.set_route = model_floyd_set_route;
1503 new_component->generic_routing.set_ASroute = model_floyd_set_route;
1504 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1505 new_component->generic_routing.get_route = floyd_get_route;
1506 new_component->generic_routing.get_latency = generic_get_link_latency;
1507 new_component->generic_routing.get_onelink_routes =
1508 floyd_get_onelink_routes;
1509 new_component->generic_routing.get_bypass_route =
1510 generic_get_bypassroute;
1511 new_component->generic_routing.finalize = floyd_finalize;
1512 new_component->generic_routing.to_index = xbt_dict_new();
1513 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1514 return new_component;
1517 static void model_floyd_load(void)
1519 /* use "surfxml_add_callback" to add a parse function call */
1522 static void model_floyd_unload(void)
1524 /* use "surfxml_del_callback" to remove a parse function call */
1527 static void model_floyd_end(void)
1530 routing_component_floyd_t routing =
1531 ((routing_component_floyd_t) current_routing);
1533 unsigned int i, j, a, b, c;
1535 /* set the size of table routing */
1536 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1538 if(!routing->link_table)
1540 /* Create Cost, Predecessor and Link tables */
1541 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1542 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1543 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1545 /* Initialize costs and predecessors */
1546 for (i = 0; i < table_size; i++)
1547 for (j = 0; j < table_size; j++) {
1548 TO_FLOYD_COST(i, j) = DBL_MAX;
1549 TO_FLOYD_PRED(i, j) = -1;
1550 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1554 /* Add the loopback if needed */
1555 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1556 for (i = 0; i < table_size; i++) {
1557 route_extended_t e_route = TO_FLOYD_LINK(i, i);
1559 e_route = xbt_new0(s_route_extended_t, 1);
1560 e_route->src_gateway = NULL;
1561 e_route->dst_gateway = NULL;
1562 e_route->generic_route.link_list =
1563 xbt_dynar_new(global_routing->size_of_link, NULL);
1564 xbt_dynar_push(e_route->generic_route.link_list,
1565 &global_routing->loopback);
1566 TO_FLOYD_LINK(i, i) = e_route;
1567 TO_FLOYD_PRED(i, i) = i;
1568 TO_FLOYD_COST(i, i) = 1;
1572 /* Calculate path costs */
1573 for (c = 0; c < table_size; c++) {
1574 for (a = 0; a < table_size; a++) {
1575 for (b = 0; b < table_size; b++) {
1576 if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
1577 if (TO_FLOYD_COST(a, b) == DBL_MAX ||
1578 (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
1579 TO_FLOYD_COST(a, b))) {
1580 TO_FLOYD_COST(a, b) =
1581 TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
1582 TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
1590 static void model_floyd_set_route(routing_component_t rc, const char *src,
1591 const char *dst, name_route_extended_t route)
1593 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1595 /* set the size of table routing */
1596 size_t table_size = xbt_dict_length(rc->to_index);
1597 int *src_id, *dst_id;
1600 src_id = xbt_dict_get_or_null(rc->to_index, src);
1601 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1603 if(!routing->link_table)
1605 /* Create Cost, Predecessor and Link tables */
1606 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1607 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1608 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1610 /* Initialize costs and predecessors */
1611 for (i = 0; i < table_size; i++)
1612 for (j = 0; j < table_size; j++) {
1613 TO_FLOYD_COST(i, j) = DBL_MAX;
1614 TO_FLOYD_PRED(i, j) = -1;
1615 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1619 if(TO_FLOYD_LINK(*src_id, *dst_id))
1621 if(!route->dst_gateway && !route->src_gateway)
1622 DEBUG2("See Route from \"%s\" to \"%s\"", src, dst);
1624 DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1625 route->src_gateway, dst, route->dst_gateway);
1628 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1629 xbt_dynar_foreach(route->generic_route.link_list,cpt,link_name)
1631 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1632 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1633 xbt_dynar_push(link_route_to_test,&link);
1635 xbt_assert2(!xbt_dynar_compare(
1636 (void*)TO_FLOYD_LINK(*src_id, *dst_id)->generic_route.link_list,
1637 (void*)link_route_to_test,
1638 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1639 "The route between \"%s\" and \"%s\" already exists", src,dst);
1640 xbt_free(link_route_to_test);
1644 if(!route->dst_gateway && !route->src_gateway)
1645 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1647 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1648 route->src_gateway, dst, route->dst_gateway);
1650 TO_FLOYD_LINK(*src_id, *dst_id) =
1651 generic_new_extended_route(rc->hierarchy, route, 1);
1652 TO_FLOYD_PRED(*src_id, *dst_id) = *src_id;
1653 TO_FLOYD_COST(*src_id, *dst_id) =
1654 ((TO_FLOYD_LINK(*src_id, *dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1657 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1658 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1660 if(TO_FLOYD_LINK(*dst_id, *src_id))
1662 if(!route->dst_gateway && !route->src_gateway)
1663 DEBUG2("See Route from \"%s\" to \"%s\"", dst, src);
1665 DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1666 route->src_gateway, src, route->dst_gateway);
1669 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1670 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1672 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1673 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1674 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1675 xbt_dynar_push(link_route_to_test,&link);
1677 xbt_assert2(!xbt_dynar_compare(
1678 (void*)TO_FLOYD_LINK(*dst_id, *src_id)->generic_route.link_list,
1679 (void*)link_route_to_test,
1680 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1681 "The route between \"%s\" and \"%s\" already exists", src,dst);
1682 xbt_free(link_route_to_test);
1686 if(route->dst_gateway && route->src_gateway)
1688 char * gw_src = bprintf("%s",route->src_gateway);
1689 char * gw_dst = bprintf("%s",route->dst_gateway);
1690 route->src_gateway = bprintf("%s",gw_dst);
1691 route->dst_gateway = bprintf("%s",gw_src);
1694 if(!route->dst_gateway && !route->src_gateway)
1695 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1697 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1698 route->src_gateway, src, route->dst_gateway);
1700 TO_FLOYD_LINK(*dst_id, *src_id) =
1701 generic_new_extended_route(rc->hierarchy, route, 0);
1702 TO_FLOYD_PRED(*dst_id, *src_id) = *dst_id;
1703 TO_FLOYD_COST(*dst_id, *src_id) =
1704 ((TO_FLOYD_LINK(*dst_id, *src_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1709 /* ************************************************************************** */
1710 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1713 s_routing_component_t generic_routing;
1714 xbt_graph_t route_graph; /* xbt_graph */
1715 xbt_dict_t graph_node_map; /* map */
1716 xbt_dict_t route_cache; /* use in cache mode */
1718 } s_routing_component_dijkstra_t, *routing_component_dijkstra_t;
1721 typedef struct graph_node_data {
1723 int graph_id; /* used for caching internal graph id's */
1724 } s_graph_node_data_t, *graph_node_data_t;
1726 typedef struct graph_node_map_element {
1728 } s_graph_node_map_element_t, *graph_node_map_element_t;
1730 typedef struct route_cache_element {
1733 } s_route_cache_element_t, *route_cache_element_t;
1735 /* Free functions */
1737 static void route_cache_elem_free(void *e)
1739 route_cache_element_t elm = (route_cache_element_t) e;
1741 xbt_free(elm->pred_arr);
1746 static void graph_node_map_elem_free(void *e)
1748 graph_node_map_element_t elm = (graph_node_map_element_t) e;
1754 static void graph_edge_data_free(void *e)
1756 route_extended_t e_route = (route_extended_t) e;
1758 xbt_dynar_free(&(e_route->generic_route.link_list));
1759 if (e_route->src_gateway)
1760 xbt_free(e_route->src_gateway);
1761 if (e_route->dst_gateway)
1762 xbt_free(e_route->dst_gateway);
1767 /* Utility functions */
1769 static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc,
1770 int id, int graph_id)
1772 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1773 xbt_node_t node = NULL;
1774 graph_node_data_t data = NULL;
1775 graph_node_map_element_t elm = NULL;
1777 data = xbt_new0(struct graph_node_data, 1);
1779 data->graph_id = graph_id;
1780 node = xbt_graph_new_node(routing->route_graph, data);
1782 elm = xbt_new0(struct graph_node_map_element, 1);
1784 xbt_dict_set_ext(routing->graph_node_map, (char *) (&id), sizeof(int),
1785 (xbt_set_elm_t) elm, &graph_node_map_elem_free);
1790 static graph_node_map_element_t
1791 graph_node_map_search(routing_component_dijkstra_t rc, int id)
1793 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1794 graph_node_map_element_t elm = (graph_node_map_element_t)
1795 xbt_dict_get_or_null_ext(routing->graph_node_map,
1803 static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id,
1804 int dst_id, route_extended_t e_route)
1806 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1808 xbt_node_t src = NULL;
1809 xbt_node_t dst = NULL;
1810 graph_node_map_element_t src_elm = (graph_node_map_element_t)
1811 xbt_dict_get_or_null_ext(routing->graph_node_map,
1814 graph_node_map_element_t dst_elm = (graph_node_map_element_t)
1815 xbt_dict_get_or_null_ext(routing->graph_node_map,
1820 src = src_elm->node;
1823 dst = dst_elm->node;
1825 /* add nodes if they don't exist in the graph */
1826 if (src_id == dst_id && src == NULL && dst == NULL) {
1827 src = route_graph_new_node(rc, src_id, -1);
1831 src = route_graph_new_node(rc, src_id, -1);
1834 dst = route_graph_new_node(rc, dst_id, -1);
1838 /* add link as edge to graph */
1839 xbt_graph_new_edge(routing->route_graph, src, dst, e_route);
1842 static void add_loopback_dijkstra(routing_component_dijkstra_t rc)
1844 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1846 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1848 xbt_node_t node = NULL;
1849 unsigned int cursor2;
1850 xbt_dynar_foreach(nodes, cursor2, node) {
1851 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1852 xbt_edge_t edge = NULL;
1853 unsigned int cursor;
1856 xbt_dynar_foreach(out_edges, cursor, edge) {
1857 xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1858 if (other_node == node) {
1865 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
1866 e_route->src_gateway = NULL;
1867 e_route->dst_gateway = NULL;
1868 e_route->generic_route.link_list =
1869 xbt_dynar_new(global_routing->size_of_link, NULL);
1870 xbt_dynar_push(e_route->generic_route.link_list,
1871 &global_routing->loopback);
1872 xbt_graph_new_edge(routing->route_graph, node, node, e_route);
1877 /* Business methods */
1878 static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
1880 xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
1883 static route_extended_t dijkstra_get_route(routing_component_t rc,
1887 xbt_assert1(rc && src
1889 "Invalid params for \"get_route\" function at AS \"%s\"",
1892 /* set utils vars */
1893 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1895 generic_src_dst_check(rc, src, dst);
1896 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1897 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1900 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1903 /* create a result route */
1904 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1905 new_e_route->generic_route.link_list =
1906 xbt_dynar_new(global_routing->size_of_link, NULL);
1907 new_e_route->src_gateway = NULL;
1908 new_e_route->dst_gateway = NULL;
1910 int *pred_arr = NULL;
1911 int src_node_id = 0;
1912 int dst_node_id = 0;
1915 route_extended_t e_route;
1919 xbt_dynar_t links = NULL;
1920 route_cache_element_t elm = NULL;
1921 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1923 /* Use the graph_node id mapping set to quickly find the nodes */
1924 graph_node_map_element_t src_elm =
1925 graph_node_map_search(routing, *src_id);
1926 graph_node_map_element_t dst_elm =
1927 graph_node_map_search(routing, *dst_id);
1928 xbt_assert2(src_elm != NULL
1929 && dst_elm != NULL, "src %d or dst %d does not exist",
1931 src_node_id = ((graph_node_data_t)
1932 xbt_graph_node_get_data(src_elm->node))->graph_id;
1933 dst_node_id = ((graph_node_data_t)
1934 xbt_graph_node_get_data(dst_elm->node))->graph_id;
1936 /* if the src and dst are the same *//* fixed, missing in the previous version */
1937 if (src_node_id == dst_node_id) {
1939 xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
1940 xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
1942 xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v);
1944 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
1947 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
1949 links = e_route->generic_route.link_list;
1950 xbt_dynar_foreach(links, cpt, link) {
1951 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1957 if (routing->cached) {
1958 /*check if there is a cached predecessor list avail */
1959 elm = (route_cache_element_t)
1960 xbt_dict_get_or_null_ext(routing->route_cache, (char *) (&src_id),
1964 if (elm) { /* cached mode and cache hit */
1965 pred_arr = elm->pred_arr;
1966 } else { /* not cached mode or cache miss */
1967 double *cost_arr = NULL;
1968 xbt_heap_t pqueue = NULL;
1971 int nr_nodes = xbt_dynar_length(nodes);
1972 cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
1973 pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
1974 pqueue = xbt_heap_new(nr_nodes, xbt_free);
1977 cost_arr[src_node_id] = 0.0;
1979 for (i = 0; i < nr_nodes; i++) {
1980 if (i != src_node_id) {
1981 cost_arr[i] = DBL_MAX;
1986 /* initialize priority queue */
1987 nodeid = xbt_new0(int, 1);
1989 xbt_heap_push(pqueue, nodeid, cost_arr[i]);
1993 /* apply dijkstra using the indexes from the graph's node array */
1994 while (xbt_heap_size(pqueue) > 0) {
1995 int *v_id = xbt_heap_pop(pqueue);
1996 xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
1997 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
1998 xbt_edge_t edge = NULL;
1999 unsigned int cursor;
2001 xbt_dynar_foreach(out_edges, cursor, edge) {
2002 xbt_node_t u_node = xbt_graph_edge_get_target(edge);
2003 graph_node_data_t data = xbt_graph_node_get_data(u_node);
2004 int u_id = data->graph_id;
2005 route_extended_t tmp_e_route =
2006 (route_extended_t) xbt_graph_edge_get_data(edge);
2007 int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */
2009 if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
2010 pred_arr[u_id] = *v_id;
2011 cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
2012 nodeid = xbt_new0(int, 1);
2014 xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
2018 /* free item popped from pqueue */
2023 xbt_heap_free(pqueue);
2026 /* compose route path with links */
2027 char *gw_src = NULL, *gw_dst =
2028 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
2030 for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
2031 xbt_node_t node_pred_v =
2032 xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
2033 xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
2035 xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
2037 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
2040 prev_gw_src = gw_src;
2041 prev_gw_dst = gw_dst;
2043 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
2044 gw_src = e_route->src_gateway;
2045 gw_dst = e_route->dst_gateway;
2047 if (v == dst_node_id)
2050 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
2051 && strcmp(gw_dst, prev_gw_src)) {
2052 xbt_dynar_t e_route_as_to_as =
2053 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
2054 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
2055 gw_dst, prev_gw_src);
2056 links = e_route_as_to_as;
2058 xbt_dynar_foreach(links, cpt, link) {
2059 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
2065 links = e_route->generic_route.link_list;
2066 xbt_dynar_foreach(links, cpt, link) {
2067 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
2072 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
2073 new_e_route->src_gateway = xbt_strdup(gw_src);
2074 new_e_route->dst_gateway = xbt_strdup(first_gw);
2077 if (routing->cached && elm == NULL) {
2078 /* add to predecessor list of the current src-host to cache */
2079 elm = xbt_new0(struct route_cache_element, 1);
2080 elm->pred_arr = pred_arr;
2082 xbt_dict_set_ext(routing->route_cache, (char *) (&src_id), sizeof(int),
2083 (xbt_set_elm_t) elm, &route_cache_elem_free);
2086 if (!routing->cached)
2092 static void dijkstra_finalize(routing_component_t rc)
2094 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2097 xbt_graph_free_graph(routing->route_graph, &xbt_free,
2098 &graph_edge_data_free, &xbt_free);
2099 xbt_dict_free(&routing->graph_node_map);
2100 if (routing->cached)
2101 xbt_dict_free(&routing->route_cache);
2102 /* Delete bypass dict */
2103 xbt_dict_free(&routing->generic_routing.bypassRoutes);
2104 /* Delete index dict */
2105 xbt_dict_free(&(routing->generic_routing.to_index));
2106 /* Delete structure */
2111 /* Creation routing model functions */
2113 static void *model_dijkstra_both_create(int cached)
2115 routing_component_dijkstra_t new_component =
2116 xbt_new0(s_routing_component_dijkstra_t, 1);
2117 new_component->generic_routing.set_processing_unit =
2118 generic_set_processing_unit;
2119 new_component->generic_routing.set_autonomous_system =
2120 generic_set_autonomous_system;
2121 new_component->generic_routing.set_route = model_dijkstra_both_set_route;
2122 new_component->generic_routing.set_ASroute = model_dijkstra_both_set_route; //TODO
2123 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
2124 new_component->generic_routing.get_route = dijkstra_get_route;
2125 new_component->generic_routing.get_latency = generic_get_link_latency;
2126 new_component->generic_routing.get_onelink_routes =
2127 dijkstra_get_onelink_routes;
2128 new_component->generic_routing.get_bypass_route =
2129 generic_get_bypassroute;
2130 new_component->generic_routing.finalize = dijkstra_finalize;
2131 new_component->cached = cached;
2132 new_component->generic_routing.to_index = xbt_dict_new();
2133 new_component->generic_routing.bypassRoutes = xbt_dict_new();
2134 return new_component;
2137 static void *model_dijkstra_create(void)
2139 return model_dijkstra_both_create(0);
2142 static void *model_dijkstracache_create(void)
2144 return model_dijkstra_both_create(1);
2147 static void model_dijkstra_both_load(void)
2149 /* use "surfxml_add_callback" to add a parse function call */
2152 static void model_dijkstra_both_unload(void)
2154 /* use "surfxml_del_callback" to remove a parse function call */
2157 static void model_dijkstra_both_end(void)
2159 routing_component_dijkstra_t routing =
2160 (routing_component_dijkstra_t) current_routing;
2162 xbt_node_t node = NULL;
2163 unsigned int cursor2;
2164 xbt_dynar_t nodes = NULL;
2166 /* Create the topology graph */
2167 routing->route_graph = xbt_graph_new_graph(1, NULL);
2168 routing->graph_node_map = xbt_dict_new();
2170 if (routing->cached && !routing->route_cache)
2171 routing->route_cache = xbt_dict_new();
2173 /* Add the loopback if needed */
2174 if (current_routing->hierarchy == SURF_ROUTING_BASE)
2175 add_loopback_dijkstra(routing);
2177 /* initialize graph indexes in nodes after graph has been built */
2178 nodes = xbt_graph_get_nodes(routing->route_graph);
2180 xbt_dynar_foreach(nodes, cursor2, node) {
2181 graph_node_data_t data = xbt_graph_node_get_data(node);
2182 data->graph_id = cursor2;
2186 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
2187 const char *dst, name_route_extended_t route)
2189 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2190 int *src_id, *dst_id;
2191 src_id = xbt_dict_get_or_null(rc->to_index, src);
2192 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
2194 if (routing->cached && !routing->route_cache)
2195 routing->route_cache = xbt_dict_new();
2197 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
2198 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
2199 xbt_die("Route symmetrical not supported on model dijkstra");
2201 if(!route->dst_gateway && !route->src_gateway)
2202 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
2204 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
2205 route->src_gateway, dst, route->dst_gateway);
2207 route_extended_t e_route =
2208 generic_new_extended_route(current_routing->hierarchy, route, 1);
2209 route_new_dijkstra(routing, *src_id, *dst_id, e_route);
2212 #ifdef HAVE_PCRE_LIB
2213 /* ************************************************** */
2214 /* ************** RULE-BASED ROUTING **************** */
2216 /* Routing model structure */
2219 s_routing_component_t generic_routing;
2220 xbt_dict_t dict_processing_units;
2221 xbt_dict_t dict_autonomous_systems;
2222 xbt_dynar_t list_route;
2223 xbt_dynar_t list_ASroute;
2224 } s_routing_component_rulebased_t, *routing_component_rulebased_t;
2226 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
2227 typedef struct s_rule_route_extended s_rule_route_extended_t,
2228 *rule_route_extended_t;
2230 struct s_rule_route {
2231 xbt_dynar_t re_str_link; // dynar of char*
2236 struct s_rule_route_extended {
2237 s_rule_route_t generic_rule_route;
2238 char *re_src_gateway;
2239 char *re_dst_gateway;
2242 static void rule_route_free(void *e)
2244 rule_route_t *elem = (rule_route_t *) (e);
2246 xbt_dynar_free(&(*elem)->re_str_link);
2247 pcre_free((*elem)->re_src);
2248 pcre_free((*elem)->re_dst);
2254 static void rule_route_extended_free(void *e)
2256 rule_route_extended_t *elem = (rule_route_extended_t *) e;
2258 xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link);
2259 pcre_free((*elem)->generic_rule_route.re_src);
2260 pcre_free((*elem)->generic_rule_route.re_dst);
2261 xbt_free((*elem)->re_src_gateway);
2262 xbt_free((*elem)->re_dst_gateway);
2267 /* Parse routing model functions */
2269 static void model_rulebased_set_processing_unit(routing_component_t rc,
2272 routing_component_rulebased_t routing =
2273 (routing_component_rulebased_t) rc;
2274 xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
2277 static void model_rulebased_set_autonomous_system(routing_component_t rc,
2280 routing_component_rulebased_t routing =
2281 (routing_component_rulebased_t) rc;
2282 xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
2286 static void model_rulebased_set_route(routing_component_t rc,
2287 const char *src, const char *dst,
2288 name_route_extended_t route)
2290 routing_component_rulebased_t routing =
2291 (routing_component_rulebased_t) rc;
2292 rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
2295 ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL);
2296 xbt_assert3(ruleroute->re_src,
2297 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2298 erroffset, src, error);
2299 ruleroute->re_dst = pcre_compile(dst, 0, &error, &erroffset, NULL);
2300 xbt_assert3(ruleroute->re_src,
2301 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2302 erroffset, dst, error);
2303 ruleroute->re_str_link = route->generic_route.link_list;
2304 xbt_dynar_push(routing->list_route, &ruleroute);
2308 static void model_rulebased_set_ASroute(routing_component_t rc,
2309 const char *src, const char *dst,
2310 name_route_extended_t route)
2312 routing_component_rulebased_t routing =
2313 (routing_component_rulebased_t) rc;
2314 rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
2317 ruleroute_e->generic_rule_route.re_src =
2318 pcre_compile(src, 0, &error, &erroffset, NULL);
2319 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2320 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2321 erroffset, src, error);
2322 ruleroute_e->generic_rule_route.re_dst =
2323 pcre_compile(dst, 0, &error, &erroffset, NULL);
2324 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2325 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2326 erroffset, dst, error);
2327 ruleroute_e->generic_rule_route.re_str_link =
2328 route->generic_route.link_list;
2329 ruleroute_e->re_src_gateway = route->src_gateway;
2330 ruleroute_e->re_dst_gateway = route->dst_gateway;
2331 xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
2332 xbt_free(route->src_gateway);
2333 xbt_free(route->dst_gateway);
2337 static void model_rulebased_set_bypassroute(routing_component_t rc,
2340 route_extended_t e_route)
2342 xbt_die("bypass routing not supported for Route-Based model");
2345 #define BUFFER_SIZE 4096 /* result buffer size */
2346 #define OVECCOUNT 30 /* should be a multiple of 3 */
2348 static char *remplace(char *value, const char **src_list, int src_size,
2349 const char **dst_list, int dst_size)
2352 char result_result[BUFFER_SIZE];
2353 int i_result_buffer;
2354 int value_length = (int) strlen(value);
2358 i_result_buffer = 0;
2360 if (value[i] == '$') {
2364 int number_length = 0;
2365 while ('0' <= value[i + number_length]
2366 && value[i + number_length] <= '9') {
2369 xbt_assert2(number_length != 0,
2370 "bad string parameter, no number indication, at offset: %d (\"%s\")",
2374 number = atoi(value + i);
2375 i = i + number_length;
2376 xbt_assert2(i + 2 < value_length,
2377 "bad string parameter, too few chars, at offset: %d (\"%s\")",
2380 // solve the indication
2381 const char **param_list;
2383 if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') {
2384 param_list = src_list;
2385 param_size = src_size;
2386 } else if (value[i] == 'd' && value[i + 1] == 's'
2387 && value[i + 2] == 't') {
2388 param_list = dst_list;
2389 param_size = dst_size;
2392 "bad string parameter, support only \"src\" and \"dst\", at offset: %d (\"%s\")",
2397 xbt_assert4(param_size >= number,
2398 "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",
2399 i, value, param_size, number);
2401 const char *param = param_list[number];
2402 int size = strlen(param);
2404 for (cp = 0; cp < size; cp++) {
2405 result_result[i_result_buffer] = param[cp];
2407 if (i_result_buffer >= BUFFER_SIZE)
2411 result_result[i_result_buffer] = value[i];
2416 } while (i < value_length && i_result_buffer < BUFFER_SIZE);
2418 xbt_assert2(i_result_buffer < BUFFER_SIZE,
2419 "solving string \"%s\", small buffer size (%d)", value,
2421 result_result[i_result_buffer] = 0;
2422 return xbt_strdup(result_result);
2425 static route_extended_t rulebased_get_route(routing_component_t rc,
2428 static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
2430 xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
2431 routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
2433 xbt_dict_cursor_t c1 = NULL;
2437 char *router = NULL;
2438 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2439 if (strstr (k1, "router")){
2444 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2447 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2448 route_extended_t route = rulebased_get_route (rc, router, k1);
2450 int number_of_links = xbt_dynar_length(route->generic_route.link_list);
2451 if (number_of_links != 3) {
2452 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2456 xbt_dynar_get_cpy (route->generic_route.link_list, 2, &link_ptr);
2457 onelink_t onelink = xbt_new0 (s_onelink_t, 1);
2458 onelink->src = xbt_strdup (k1);
2459 onelink->dst = xbt_strdup (router);
2460 onelink->link_ptr = link_ptr;
2461 xbt_dynar_push (ret, &onelink);
2466 /* Business methods */
2467 static route_extended_t rulebased_get_route(routing_component_t rc,
2471 xbt_assert1(rc && src
2473 "Invalid params for \"get_route\" function at AS \"%s\"",
2476 /* set utils vars */
2477 routing_component_rulebased_t routing =
2478 (routing_component_rulebased_t) rc;
2480 int are_processing_units;
2481 xbt_dynar_t rule_list;
2482 if (xbt_dict_get_or_null(routing->dict_processing_units, src)
2483 && xbt_dict_get_or_null(routing->dict_processing_units, dst)) {
2484 are_processing_units = 1;
2485 rule_list = routing->list_route;
2486 } else if (xbt_dict_get_or_null(routing->dict_autonomous_systems, src)
2487 && xbt_dict_get_or_null(routing->dict_autonomous_systems,
2489 are_processing_units = 0;
2490 rule_list = routing->list_ASroute;
2493 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
2498 int src_length = (int) strlen(src);
2499 int dst_length = (int) strlen(dst);
2501 xbt_dynar_t links_list =
2502 xbt_dynar_new(global_routing->size_of_link, NULL);
2504 rule_route_t ruleroute;
2506 int ovector_src[OVECCOUNT];
2507 int ovector_dst[OVECCOUNT];
2508 const char **list_src = NULL;
2509 const char **list_dst = NULL;
2510 xbt_dynar_foreach(rule_list, cpt, ruleroute) {
2512 pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0,
2513 ovector_src, OVECCOUNT);
2516 pcre_exec(ruleroute->re_dst, NULL, dst, dst_length, 0, 0,
2517 ovector_dst, OVECCOUNT);
2519 xbt_assert1(!pcre_get_substring_list
2520 (src, ovector_src, rc_src, &list_src),
2521 "error solving substring list for src \"%s\"", src);
2522 xbt_assert1(!pcre_get_substring_list
2523 (dst, ovector_dst, rc_dst, &list_dst),
2524 "error solving substring list for src \"%s\"", dst);
2526 xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) {
2527 char *new_link_name =
2528 remplace(link_name, list_src, rc_src, list_dst, rc_dst);
2530 xbt_dict_get_or_null(surf_network_model->resource_set,
2533 xbt_dynar_push(links_list, &link);
2535 THROW1(mismatch_error, 0, "Link %s not found", new_link_name);
2536 xbt_free(new_link_name);
2540 if (rc_src >= 0 && rc_dst >= 0)
2544 route_extended_t new_e_route = NULL;
2545 if (rc_src >= 0 && rc_dst >= 0) {
2546 new_e_route = xbt_new0(s_route_extended_t, 1);
2547 new_e_route->generic_route.link_list = links_list;
2548 } else if (!strcmp(src, dst) && are_processing_units) {
2549 new_e_route = xbt_new0(s_route_extended_t, 1);
2550 xbt_dynar_push(links_list, &(global_routing->loopback));
2551 new_e_route->generic_route.link_list = links_list;
2553 xbt_dynar_free(&link_list);
2556 if (!are_processing_units && new_e_route) {
2557 rule_route_extended_t ruleroute_extended =
2558 (rule_route_extended_t) ruleroute;
2559 new_e_route->src_gateway =
2560 remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
2562 new_e_route->dst_gateway =
2563 remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
2568 pcre_free_substring_list(list_src);
2570 pcre_free_substring_list(list_dst);
2575 static route_extended_t rulebased_get_bypass_route(routing_component_t rc,
2582 static void rulebased_finalize(routing_component_t rc)
2584 routing_component_rulebased_t routing =
2585 (routing_component_rulebased_t) rc;
2587 xbt_dict_free(&routing->dict_processing_units);
2588 xbt_dict_free(&routing->dict_autonomous_systems);
2589 xbt_dynar_free(&routing->list_route);
2590 xbt_dynar_free(&routing->list_ASroute);
2591 /* Delete structure */
2596 /* Creation routing model functions */
2597 static void *model_rulebased_create(void)
2599 routing_component_rulebased_t new_component =
2600 xbt_new0(s_routing_component_rulebased_t, 1);
2601 new_component->generic_routing.set_processing_unit =
2602 model_rulebased_set_processing_unit;
2603 new_component->generic_routing.set_autonomous_system =
2604 model_rulebased_set_autonomous_system;
2605 new_component->generic_routing.set_route = model_rulebased_set_route;
2606 new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
2607 new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
2608 new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
2609 new_component->generic_routing.get_route = rulebased_get_route;
2610 new_component->generic_routing.get_bypass_route = generic_get_bypassroute; //rulebased_get_bypass_route;
2611 new_component->generic_routing.finalize = rulebased_finalize;
2612 /* initialization of internal structures */
2613 new_component->dict_processing_units = xbt_dict_new();
2614 new_component->dict_autonomous_systems = xbt_dict_new();
2615 new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
2616 new_component->list_ASroute =
2617 xbt_dynar_new(sizeof(rule_route_extended_t),
2618 &rule_route_extended_free);
2619 return new_component;
2622 static void model_rulebased_load(void)
2624 /* use "surfxml_add_callback" to add a parse function call */
2627 static void model_rulebased_unload(void)
2629 /* use "surfxml_del_callback" to remove a parse function call */
2632 static void model_rulebased_end(void)
2636 #endif /* HAVE_PCRE_LIB */
2638 /* ************************************************************************** */
2639 /* ******************************* NO ROUTING ******************************* */
2641 /* Routing model structure */
2643 s_routing_component_t generic_routing;
2644 } s_routing_component_none_t, *routing_component_none_t;
2646 /* Business methods */
2647 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc)
2652 static route_extended_t none_get_route(routing_component_t rc,
2653 const char *src, const char *dst)
2658 static route_extended_t none_get_bypass_route(routing_component_t rc,
2665 static void none_finalize(routing_component_t rc)
2670 static void none_set_processing_unit(routing_component_t rc,
2675 static void none_set_autonomous_system(routing_component_t rc,
2680 /* Creation routing model functions */
2681 static void *model_none_create(void)
2683 routing_component_none_t new_component =
2684 xbt_new0(s_routing_component_none_t, 1);
2685 new_component->generic_routing.set_processing_unit =
2686 none_set_processing_unit;
2687 new_component->generic_routing.set_autonomous_system =
2688 none_set_autonomous_system;
2689 new_component->generic_routing.set_route = NULL;
2690 new_component->generic_routing.set_ASroute = NULL;
2691 new_component->generic_routing.set_bypassroute = NULL;
2692 new_component->generic_routing.get_route = none_get_route;
2693 new_component->generic_routing.get_onelink_routes =
2694 none_get_onelink_routes;
2695 new_component->generic_routing.get_bypass_route = none_get_bypass_route;
2696 new_component->generic_routing.finalize = none_finalize;
2697 return new_component;
2700 static void model_none_load(void)
2704 static void model_none_unload(void)
2708 static void model_none_end(void)
2712 /* ************************************************** */
2713 /* ********** PATERN FOR NEW ROUTING **************** */
2715 /* The minimal configuration of a new routing model need the next functions,
2716 * also you need to set at the start of the file, the new model in the model
2717 * list. Remember keep the null ending of the list.
2719 /*** Routing model structure ***/
2721 // s_routing_component_t generic_routing;
2722 // /* things that your routing model need */
2723 // } s_routing_component_NEW_t,*routing_component_NEW_t;
2725 /*** Parse routing model functions ***/
2726 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
2727 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
2728 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
2729 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
2730 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
2732 /*** Business methods ***/
2733 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2734 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2735 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
2737 /*** Creation routing model functions ***/
2738 // static void* model_NEW_create(void) {
2739 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
2740 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
2741 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
2742 // new_component->generic_routing.set_route = model_NEW_set_route;
2743 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
2744 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
2745 // new_component->generic_routing.get_route = NEW_get_route;
2746 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
2747 // new_component->generic_routing.finalize = NEW_finalize;
2748 // /* initialization of internal structures */
2749 // return new_component;
2750 // } /* mandatory */
2751 // static void model_NEW_load(void) {} /* mandatory */
2752 // static void model_NEW_unload(void) {} /* mandatory */
2753 // static void model_NEW_end(void) {} /* mandatory */
2755 /* ************************************************************************** */
2756 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
2758 static void generic_set_processing_unit(routing_component_t rc,
2761 DEBUG1("Load process unit \"%s\"", name);
2762 int *id = xbt_new0(int, 1);
2763 xbt_dict_t _to_index;
2764 _to_index = current_routing->to_index;
2765 *id = xbt_dict_length(_to_index);
2766 xbt_dict_set(_to_index, name, id, xbt_free);
2769 static void generic_set_autonomous_system(routing_component_t rc,
2772 DEBUG1("Load Autonomous system \"%s\"", name);
2773 int *id = xbt_new0(int, 1);
2774 xbt_dict_t _to_index;
2775 _to_index = current_routing->to_index;
2776 *id = xbt_dict_length(_to_index);
2777 xbt_dict_set(_to_index, name, id, xbt_free);
2780 static int surf_pointer_resource_cmp(const void *a, const void *b) {
2786 static int surf_link_resource_cmp(const void *a, const void *b) {
2787 if( memcmp(a,b,global_routing->size_of_link) == 0 );
2792 static void generic_set_bypassroute(routing_component_t rc,
2793 const char *src, const char *dst,
2794 route_extended_t e_route)
2796 DEBUG2("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
2797 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2800 route_name = bprintf("%s#%s", src, dst);
2801 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2802 "Invalid count of links, must be greater than zero (%s,%s)",
2804 xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
2805 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
2806 src, e_route->src_gateway, dst, e_route->dst_gateway);
2808 route_extended_t new_e_route =
2809 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
2810 xbt_dynar_free(&(e_route->generic_route.link_list));
2813 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
2814 (void (*)(void *)) generic_free_extended_route);
2815 xbt_free(route_name);
2818 /* ************************************************************************** */
2819 /* *********************** GENERIC BUSINESS METHODS ************************* */
2821 static double generic_get_link_latency(routing_component_t rc,
2822 const char *src, const char *dst)
2824 route_extended_t route = rc->get_route(rc,src,dst);
2827 double latency = 0.0;
2829 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
2830 latency += get_link_latency(link);
2835 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
2837 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
2840 static route_extended_t generic_get_bypassroute(routing_component_t rc,
2844 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2845 routing_component_t src_as, dst_as;
2846 int index_src, index_dst;
2847 xbt_dynar_t path_src = NULL;
2848 xbt_dynar_t path_dst = NULL;
2849 routing_component_t current = NULL;
2850 routing_component_t *current_src = NULL;
2851 routing_component_t *current_dst = NULL;
2853 /* (1) find the as where the src and dst are located */
2854 src_as = ((network_element_info_t)
2855 xbt_dict_get_or_null(global_routing->where_network_elements,
2856 src))->rc_component;
2857 dst_as = ((network_element_info_t)
2858 xbt_dict_get_or_null(global_routing->where_network_elements,
2859 dst))->rc_component;
2862 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
2865 /* (2) find the path to the root routing component */
2866 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
2868 while (current != NULL) {
2869 xbt_dynar_push(path_src, ¤t);
2870 current = current->routing_father;
2872 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
2874 while (current != NULL) {
2875 xbt_dynar_push(path_dst, ¤t);
2876 current = current->routing_father;
2879 /* (3) find the common father */
2880 index_src = (path_src->used) - 1;
2881 index_dst = (path_dst->used) - 1;
2882 current_src = xbt_dynar_get_ptr(path_src, index_src);
2883 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2884 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
2885 routing_component_t *tmp_src, *tmp_dst;
2886 tmp_src = xbt_dynar_pop_ptr(path_src);
2887 tmp_dst = xbt_dynar_pop_ptr(path_dst);
2890 current_src = xbt_dynar_get_ptr(path_src, index_src);
2891 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2894 int max_index_src = (path_src->used) - 1;
2895 int max_index_dst = (path_dst->used) - 1;
2897 int max_index = max(max_index_src, max_index_dst);
2900 route_extended_t e_route_bypass = NULL;
2902 for (max = 0; max <= max_index; max++) {
2903 for (i = 0; i < max; i++) {
2904 if (i <= max_index_src && max <= max_index_dst) {
2905 char *route_name = bprintf("%s#%s",
2906 (*(routing_component_t *)
2908 (path_src, i)))->name,
2909 (*(routing_component_t *)
2911 (path_dst, max)))->name);
2913 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2914 xbt_free(route_name);
2918 if (max <= max_index_src && i <= max_index_dst) {
2919 char *route_name = bprintf("%s#%s",
2920 (*(routing_component_t *)
2922 (path_src, max)))->name,
2923 (*(routing_component_t *)
2925 (path_dst, i)))->name);
2927 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2928 xbt_free(route_name);
2937 if (max <= max_index_src && max <= max_index_dst) {
2938 char *route_name = bprintf("%s#%s",
2939 (*(routing_component_t *)
2941 (path_src, max)))->name,
2942 (*(routing_component_t *)
2944 (path_dst, max)))->name);
2945 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2946 xbt_free(route_name);
2952 xbt_dynar_free(&path_src);
2953 xbt_dynar_free(&path_dst);
2955 route_extended_t new_e_route = NULL;
2957 if (e_route_bypass) {
2959 unsigned int cpt = 0;
2960 new_e_route = xbt_new0(s_route_extended_t, 1);
2961 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
2962 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
2963 new_e_route->generic_route.link_list =
2964 xbt_dynar_new(global_routing->size_of_link, NULL);
2965 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
2966 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
2973 /* ************************************************************************** */
2974 /* ************************* GENERIC AUX FUNCTIONS ************************** */
2977 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
2978 void *data, int order)
2984 xbt_dynar_t links = NULL, links_id = NULL;
2986 new_route = xbt_new0(s_route_t, 1);
2987 new_route->link_list =
2988 xbt_dynar_new(global_routing->size_of_link, NULL);
2990 xbt_assert0(hierarchy == SURF_ROUTING_BASE,
2991 "the hierarchy type is not SURF_ROUTING_BASE");
2993 links = ((route_t) data)->link_list;
2996 links_id = new_route->link_list;
2998 xbt_dynar_foreach(links, cpt, link_name) {
3001 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3004 xbt_dynar_push(links_id, &link);
3006 xbt_dynar_unshift(links_id, &link);
3008 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3014 static route_extended_t
3015 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
3016 void *data, int order)
3020 route_extended_t e_route, new_e_route;
3023 xbt_dynar_t links = NULL, links_id = NULL;
3025 new_e_route = xbt_new0(s_route_extended_t, 1);
3026 new_e_route->generic_route.link_list =
3027 xbt_dynar_new(global_routing->size_of_link, NULL);
3028 new_e_route->src_gateway = NULL;
3029 new_e_route->dst_gateway = NULL;
3031 xbt_assert0(hierarchy == SURF_ROUTING_BASE
3032 || hierarchy == SURF_ROUTING_RECURSIVE,
3033 "the hierarchy type is not defined");
3035 if (hierarchy == SURF_ROUTING_BASE) {
3037 route = (route_t) data;
3038 links = route->link_list;
3040 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
3042 e_route = (route_extended_t) data;
3043 xbt_assert0(e_route->src_gateway
3044 && e_route->dst_gateway, "bad gateway, is null");
3045 links = e_route->generic_route.link_list;
3047 /* remeber not erase the gateway names */
3048 new_e_route->src_gateway = e_route->src_gateway;
3049 new_e_route->dst_gateway = e_route->dst_gateway;
3052 links_id = new_e_route->generic_route.link_list;
3054 xbt_dynar_foreach(links, cpt, link_name) {
3057 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3060 xbt_dynar_push(links_id, &link);
3062 xbt_dynar_unshift(links_id, &link);
3064 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3070 static void generic_free_route(route_t route)
3073 xbt_dynar_free(&(route->link_list));
3078 static void generic_free_extended_route(route_extended_t e_route)
3081 xbt_dynar_free(&(e_route->generic_route.link_list));
3082 if (e_route->src_gateway)
3083 xbt_free(e_route->src_gateway);
3084 if (e_route->dst_gateway)
3085 xbt_free(e_route->dst_gateway);
3090 static routing_component_t generic_as_exist(routing_component_t find_from,
3091 routing_component_t to_find)
3093 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3094 xbt_dict_cursor_t cursor = NULL;
3097 routing_component_t elem;
3098 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
3099 if (to_find == elem || generic_as_exist(elem, to_find)) {
3109 static routing_component_t
3110 generic_autonomous_system_exist(routing_component_t rc, char *element)
3112 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3113 routing_component_t element_as, result, elem;
3114 xbt_dict_cursor_t cursor = NULL;
3116 element_as = ((network_element_info_t)
3117 xbt_dict_get_or_null
3118 (global_routing->where_network_elements,
3119 element))->rc_component;
3120 result = ((routing_component_t) - 1);
3121 if (element_as != rc)
3122 result = generic_as_exist(rc, element_as);
3126 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
3127 found = !strcmp(elem->name, element);
3137 static routing_component_t
3138 generic_processing_units_exist(routing_component_t rc, char *element)
3140 routing_component_t element_as;
3141 element_as = ((network_element_info_t)
3142 xbt_dict_get_or_null
3143 (global_routing->where_network_elements,
3144 element))->rc_component;
3145 if (element_as == rc)
3147 return generic_as_exist(rc, element_as);
3150 static void generic_src_dst_check(routing_component_t rc, const char *src,
3154 routing_component_t src_as = ((network_element_info_t)
3155 xbt_dict_get_or_null
3156 (global_routing->where_network_elements,
3157 src))->rc_component;
3158 routing_component_t dst_as = ((network_element_info_t)
3159 xbt_dict_get_or_null
3160 (global_routing->where_network_elements,
3161 dst))->rc_component;
3163 xbt_assert3(src_as != NULL && dst_as != NULL,
3164 "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
3165 src, dst, rc->name);
3166 xbt_assert4(src_as == dst_as,
3167 "The src(%s in %s) and dst(%s in %s) are in differents AS",
3168 src, src_as->name, dst, dst_as->name);
3169 xbt_assert2(rc == dst_as,
3170 "The routing component of src and dst is not the same as the network elements belong (%s==%s)",
3171 rc->name, dst_as->name);
3174 static void routing_parse_Sconfig(void)
3177 DEBUG0("WARNING tag config not yet implemented.");
3178 DEBUG1("Configuration name = %s",A_surfxml_config_id);
3181 static void routing_parse_Econfig(void)
3184 xbt_dict_cursor_t cursor = NULL;
3187 xbt_dict_foreach(current_property_set, cursor, key, elem) {
3188 DEBUG2("property : %s = %s",key,elem);
3192 static void routing_parse_Scluster(void)
3194 static int AX_ptr = 0;
3196 char *cluster_id = A_surfxml_cluster_id;
3197 char *cluster_prefix = A_surfxml_cluster_prefix;
3198 char *cluster_suffix = A_surfxml_cluster_suffix;
3199 char *cluster_radical = A_surfxml_cluster_radical;
3200 char *cluster_power = A_surfxml_cluster_power;
3201 char *cluster_bw = A_surfxml_cluster_bw;
3202 char *cluster_lat = A_surfxml_cluster_lat;
3203 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
3204 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
3205 char *host_id, *groups, *link_id = NULL;
3206 char *router_id, *link_router, *link_backbone;
3207 #ifdef HAVE_PCRE_LIB
3208 char *route_src_dst;
3212 xbt_dynar_t radical_elements;
3213 xbt_dynar_t radical_ends;
3214 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
3215 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
3217 #ifndef HAVE_PCRE_LIB
3218 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3219 char *route_src, *route_dst;
3223 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3224 static unsigned int surfxml_buffer_stack_stack[1024];
3226 surfxml_buffer_stack_stack[0] = 0;
3228 surfxml_bufferstack_push(1);
3230 SURFXML_BUFFER_SET(AS_id, cluster_id);
3231 #ifdef HAVE_PCRE_LIB
3232 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3233 DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
3235 SURFXML_BUFFER_SET(AS_routing, "Full");
3236 DEBUG1("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
3238 SURFXML_START_TAG(AS);
3240 radical_elements = xbt_str_split(cluster_radical, ",");
3241 xbt_dynar_foreach(radical_elements, iter, groups) {
3242 radical_ends = xbt_str_split(groups, "-");
3243 switch (xbt_dynar_length(radical_ends)) {
3245 surf_parse_get_int(&start,
3246 xbt_dynar_get_as(radical_ends, 0, char *));
3247 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
3248 #ifndef HAVE_PCRE_LIB
3249 xbt_dynar_push_as(tab_elements_num, int, start);
3251 link_id = bprintf("%s_link_%d", cluster_id, start);
3253 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, cluster_power);
3254 A_surfxml_host_state = A_surfxml_host_state_ON;
3255 SURFXML_BUFFER_SET(host_id, host_id);
3256 SURFXML_BUFFER_SET(host_power, cluster_power);
3257 SURFXML_BUFFER_SET(host_availability, "1.0");
3258 SURFXML_BUFFER_SET(host_availability_file, "");
3259 SURFXML_BUFFER_SET(host_state_file, "");
3260 SURFXML_START_TAG(host);
3261 SURFXML_END_TAG(host);
3263 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3264 A_surfxml_link_state = A_surfxml_link_state_ON;
3265 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3266 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3267 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3268 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3269 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3270 SURFXML_BUFFER_SET(link_id, link_id);
3271 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3272 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3273 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3274 SURFXML_BUFFER_SET(link_latency_file, "");
3275 SURFXML_BUFFER_SET(link_state_file, "");
3276 SURFXML_START_TAG(link);
3277 SURFXML_END_TAG(link);
3283 surf_parse_get_int(&start,
3284 xbt_dynar_get_as(radical_ends, 0, char *));
3285 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3286 DEBUG2("Create hosts and links from %d to %d", start, end);
3287 for (i = start; i <= end; i++) {
3288 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
3289 #ifndef HAVE_PCRE_LIB
3290 xbt_dynar_push_as(tab_elements_num, int, i);
3292 link_id = bprintf("%s_link_%d", cluster_id, i);
3294 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, cluster_power);
3295 A_surfxml_host_state = A_surfxml_host_state_ON;
3296 SURFXML_BUFFER_SET(host_id, host_id);
3297 SURFXML_BUFFER_SET(host_power, cluster_power);
3298 SURFXML_BUFFER_SET(host_availability, "1.0");
3299 SURFXML_BUFFER_SET(host_availability_file, "");
3300 SURFXML_BUFFER_SET(host_state_file, "");
3301 SURFXML_START_TAG(host);
3302 SURFXML_END_TAG(host);
3304 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3305 A_surfxml_link_state = A_surfxml_link_state_ON;
3306 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3307 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3308 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3309 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3310 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3311 SURFXML_BUFFER_SET(link_id, link_id);
3312 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3313 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3314 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3315 SURFXML_BUFFER_SET(link_latency_file, "");
3316 SURFXML_BUFFER_SET(link_state_file, "");
3317 SURFXML_START_TAG(link);
3318 SURFXML_END_TAG(link);
3323 DEBUG0("Malformed radical");
3326 xbt_dynar_free(&radical_ends);
3331 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
3333 link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
3334 link_backbone = bprintf("%s_backbone", cluster_id);
3336 DEBUG1("<router id=\"%s\"/>", router_id);
3337 SURFXML_BUFFER_SET(router_id, router_id);;
3338 SURFXML_START_TAG(router);
3339 SURFXML_END_TAG(router);
3341 DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,cluster_bw, cluster_lat);
3342 A_surfxml_link_state = A_surfxml_link_state_ON;
3343 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3344 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3345 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3346 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3347 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3348 SURFXML_BUFFER_SET(link_id, link_router);
3349 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3350 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3351 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3352 SURFXML_BUFFER_SET(link_latency_file, "");
3353 SURFXML_BUFFER_SET(link_state_file, "");
3354 SURFXML_START_TAG(link);
3355 SURFXML_END_TAG(link);
3357 DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bw, cluster_lat);
3358 A_surfxml_link_state = A_surfxml_link_state_ON;
3359 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3360 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
3361 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3362 SURFXML_BUFFER_SET(link_id, link_backbone);
3363 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
3364 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
3365 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3366 SURFXML_BUFFER_SET(link_latency_file, "");
3367 SURFXML_BUFFER_SET(link_state_file, "");
3368 SURFXML_START_TAG(link);
3369 SURFXML_END_TAG(link);
3373 #ifdef HAVE_PCRE_LIB
3374 char *new_suffix = bprintf("%s", "");
3376 radical_elements = xbt_str_split(cluster_suffix, ".");
3377 xbt_dynar_foreach(radical_elements, iter, groups) {
3378 if (strcmp(groups, "")) {
3379 new_suffix = bprintf("%s\\.%s", new_suffix, groups);
3382 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
3384 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
3385 DEBUG0("symmetrical=\"NO\">");
3386 SURFXML_BUFFER_SET(route_src, route_src_dst);
3387 SURFXML_BUFFER_SET(route_dst, route_src_dst);
3388 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3389 SURFXML_START_TAG(route);
3391 DEBUG1("<link_ctn\tid=\"%s_link_$1src\"/>", cluster_id);
3392 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1src", cluster_id));
3393 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3394 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3395 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3396 SURFXML_START_TAG(link_ctn);
3397 SURFXML_END_TAG(link_ctn);
3399 DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3400 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3401 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3402 SURFXML_START_TAG(link_ctn);
3403 SURFXML_END_TAG(link_ctn);
3405 DEBUG1("<link_ctn\tid=\"%s_link_$1dst\"/>", cluster_id);
3406 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1dst", cluster_id));
3407 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3408 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3409 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3410 SURFXML_START_TAG(link_ctn);
3411 SURFXML_END_TAG(link_ctn);
3414 SURFXML_END_TAG(route);
3416 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
3417 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
3418 if (i == xbt_dynar_length(tab_elements_num)) {
3419 route_src = router_id;
3422 bprintf("%s%d%s", cluster_prefix,
3423 xbt_dynar_get_as(tab_elements_num, i, int),
3427 if (j == xbt_dynar_length(tab_elements_num)) {
3428 route_dst = router_id;
3431 bprintf("%s%d%s", cluster_prefix,
3432 xbt_dynar_get_as(tab_elements_num, j, int),
3436 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
3437 DEBUG0("symmetrical=\"NO\">");
3438 SURFXML_BUFFER_SET(route_src, route_src);
3439 SURFXML_BUFFER_SET(route_dst, route_dst);
3440 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3441 SURFXML_START_TAG(route);
3443 if (i == xbt_dynar_length(tab_elements_num)) {
3444 route_src = link_router;
3447 bprintf("%s_link_%d", cluster_id,
3448 xbt_dynar_get_as(tab_elements_num, i, int));
3451 if (j == xbt_dynar_length(tab_elements_num)) {
3452 route_dst = link_router;
3455 bprintf("%s_link_%d", cluster_id,
3456 xbt_dynar_get_as(tab_elements_num, j, int));
3459 DEBUG1("<link_ctn\tid=\"%s\"/>", route_src);
3460 SURFXML_BUFFER_SET(link_ctn_id, route_src);
3461 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3462 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3463 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3464 SURFXML_START_TAG(link_ctn);
3465 SURFXML_END_TAG(link_ctn);
3467 DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3468 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3469 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3470 SURFXML_START_TAG(link_ctn);
3471 SURFXML_END_TAG(link_ctn);
3473 DEBUG1("<link_ctn\tid=\"%s\"/>", route_dst);
3474 SURFXML_BUFFER_SET(link_ctn_id, route_dst);
3475 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3476 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3477 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3478 SURFXML_START_TAG(link_ctn);
3479 SURFXML_END_TAG(link_ctn);
3482 SURFXML_END_TAG(route);
3485 xbt_dynar_free(&tab_elements_num);
3489 SURFXML_END_TAG(AS);
3492 surfxml_bufferstack_pop(1);
3496 * New methods to init the routing model component from the lua script
3500 * calling parse_S_AS_lua with lua values
3502 void routing_AS_init(const char *AS_id, const char *AS_routing)
3504 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
3508 * calling parse_E_AS_lua to fisnish the creation of routing component
3510 void routing_AS_end(const char *AS_id)
3512 parse_E_AS_lua((char *) AS_id);
3516 * add a host to the network element list
3519 void routing_add_host(const char *host_id)
3521 parse_S_host_lua((char *) host_id);
3525 * Set a new link on the actual list of link for a route or ASroute
3527 void routing_add_link(const char *link_id)
3529 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
3533 *Set the endpoints for a route
3535 void routing_set_route(const char *src_id, const char *dst_id)
3537 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
3541 * Store the route by calling parse_E_route_store_route
3543 void routing_store_route(void)
3545 parse_E_route_store_route();