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;
29 /* Prototypes of each model */
30 static void *model_full_create(void); /* create structures for full routing model */
31 static void model_full_load(void); /* load parse functions for full routing model */
32 static void model_full_unload(void); /* unload parse functions for full routing model */
33 static void model_full_end(void); /* finalize the creation of full routing model */
34 static void model_full_set_route( /* Set the route and ASroute between src and dst */
35 routing_component_t rc, const char *src, const char *dst, name_route_extended_t route);
37 static void *model_floyd_create(void); /* create structures for floyd routing model */
38 static void model_floyd_load(void); /* load parse functions for floyd routing model */
39 static void model_floyd_unload(void); /* unload parse functions for floyd routing model */
40 static void model_floyd_end(void); /* finalize the creation of floyd routing model */
41 static void model_floyd_set_route(routing_component_t rc, const char *src,
42 const char *dst, name_route_extended_t route);
44 static void *model_dijkstra_both_create(int cached); /* create by calling dijkstra or dijkstracache */
45 static void *model_dijkstra_create(void); /* create structures for dijkstra routing model */
46 static void *model_dijkstracache_create(void); /* create structures for dijkstracache routing model */
47 static void model_dijkstra_both_load(void); /* load parse functions for dijkstra routing model */
48 static void model_dijkstra_both_unload(void); /* unload parse functions for dijkstra routing model */
49 static void model_dijkstra_both_end(void); /* finalize the creation of dijkstra routing model */
50 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
51 const char *dst, name_route_extended_t route);
53 static void *model_rulebased_create(void); /* create structures for rulebased routing model */
54 static void model_rulebased_load(void); /* load parse functions for rulebased routing model */
55 static void model_rulebased_unload(void); /* unload parse functions for rulebased routing model */
56 static void model_rulebased_end(void); /* finalize the creation of rulebased routing model */
58 static void *model_none_create(void); /* none routing model */
59 static void model_none_load(void); /* none routing model */
60 static void model_none_unload(void); /* none routing model */
61 static void model_none_end(void); /* none routing model */
63 static void routing_parse_Scluster(void); /*cluster bypass */
65 static void routing_parse_Sconfig(void); /*config Tag */
66 static void routing_parse_Econfig(void); /*config Tag */
68 /* this lines are only for replace use like index in the model table */
73 SURF_MODEL_DIJKSTRACACHE,
81 /* must be finish with null and carefull if change de order */
82 struct s_model_type routing_models[] = { {"Full",
83 "Full routing data (fast, large memory requirements, fully expressive)",
89 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
90 model_floyd_create, model_floyd_load, model_floyd_unload,
93 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
94 model_dijkstra_create, model_dijkstra_both_load,
95 model_dijkstra_both_unload, model_dijkstra_both_end},
97 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
98 model_dijkstracache_create, model_dijkstra_both_load,
99 model_dijkstra_both_unload, model_dijkstra_both_end},
100 {"none", "No routing (usable with Constant network only)",
101 model_none_create, model_none_load, model_none_unload, model_none_end},
103 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
104 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
106 {NULL, NULL, NULL, NULL, NULL, NULL}
109 /* ************************************************************************** */
110 /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
112 static void generic_set_processing_unit(routing_component_t rc,
114 static void generic_set_autonomous_system(routing_component_t rc,
116 static void generic_set_route(routing_component_t rc, const char *src,
117 const char *dst, name_route_t route);
118 static void generic_set_ASroute(routing_component_t rc, const char *src,
119 const char *dst, route_extended_t e_route);
120 static void generic_set_bypassroute(routing_component_t rc,
121 const char *src, const char *dst,
122 route_extended_t e_route);
124 static int surf_link_resource_cmp(const void *a, const void *b);
125 static int surf_pointer_resource_cmp(const void *a, const void *b);
127 /* ************************************************************************** */
128 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
130 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc);
131 static route_extended_t generic_get_bypassroute(routing_component_t rc,
135 /* ************************************************************************** */
136 /* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */
138 static route_extended_t
139 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
140 void *data, int order);
141 static void generic_free_route(route_t route);
142 static void generic_free_extended_route(route_extended_t e_route);
143 static routing_component_t
144 generic_autonomous_system_exist(routing_component_t rc, char *element);
145 static routing_component_t
146 generic_processing_units_exist(routing_component_t rc, char *element);
147 static void generic_src_dst_check(routing_component_t rc, const char *src,
150 /* ************************************************************************** */
151 /* **************************** GLOBAL FUNCTIONS **************************** */
153 /* global parse functions */
154 static char *src = NULL; /* temporary store the source name of a route */
155 static char *dst = NULL; /* temporary store the destination name of a route */
156 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
157 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
158 static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
160 * \brief Add a "host" to the network element list
162 static void parse_S_host(char *host_id)
164 network_element_info_t info = NULL;
165 if (current_routing->hierarchy == SURF_ROUTING_NULL)
166 current_routing->hierarchy = SURF_ROUTING_BASE;
167 xbt_assert1(!xbt_dict_get_or_null
168 (global_routing->where_network_elements, host_id),
169 "Reading a host, processing unit \"%s\" already exist",
171 xbt_assert1(current_routing->set_processing_unit,
172 "no defined method \"set_processing_unit\" in \"%s\"",
173 current_routing->name);
174 (*(current_routing->set_processing_unit)) (current_routing, host_id);
175 info = xbt_new0(s_network_element_info_t, 1);
176 info->rc_component = current_routing;
177 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
178 xbt_dict_set(global_routing->where_network_elements, host_id,
179 (void *) info, NULL);
183 * \brief Add a host to the network element list from XML
185 static void parse_S_host_XML(void)
187 parse_S_host(A_surfxml_host_id);
191 * \brief Add a host to the network element list from lua script
193 static void parse_S_host_lua(char *host_id)
195 parse_S_host(host_id);
200 * \brief Add a "router" to the network element list
202 static void parse_S_router(void)
204 network_element_info_t info = NULL;
206 if (current_routing->hierarchy == SURF_ROUTING_NULL)
207 current_routing->hierarchy = SURF_ROUTING_BASE;
208 xbt_assert1(!xbt_dict_get_or_null
209 (global_routing->where_network_elements,
210 A_surfxml_router_id),
211 "Reading a router, processing unit \"%s\" already exist",
212 A_surfxml_router_id);
213 xbt_assert1(current_routing->set_processing_unit,
214 "no defined method \"set_processing_unit\" in \"%s\"",
215 current_routing->name);
216 (*(current_routing->set_processing_unit)) (current_routing,
217 A_surfxml_router_id);
218 info = xbt_new0(s_network_element_info_t, 1);
219 info->rc_component = current_routing;
220 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
221 xbt_dict_set(global_routing->where_network_elements, A_surfxml_router_id,
222 (void *) info, NULL);
224 TRACE_surf_host_declaration(A_surfxml_router_id, 0);
229 * \brief Set the endponints for a route
231 static void parse_S_route_new_and_endpoints(char *src_id, char *dst_id)
233 if (src != NULL && dst != NULL && link_list != NULL)
234 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
238 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0,
239 "Some limits are null in the route between \"%s\" and \"%s\"",
241 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
245 * \breif Set the endpoints for a route from XML
247 static void parse_S_route_new_and_endpoints_XML(void)
249 parse_S_route_new_and_endpoints(A_surfxml_route_src,
250 A_surfxml_route_dst);
254 * \breif Set the endpoints for a route from lua
256 static void parse_S_route_new_and_endpoints_lua(char *id_src, char *id_dst)
258 parse_S_route_new_and_endpoints(id_src, id_dst);
262 * \brief Set the endponints and gateways for a ASroute
264 static void parse_S_ASroute_new_and_endpoints(void)
266 if (src != NULL && dst != NULL && link_list != NULL)
267 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
268 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
269 src = A_surfxml_ASroute_src;
270 dst = A_surfxml_ASroute_dst;
271 gw_src = A_surfxml_ASroute_gw_src;
272 gw_dst = A_surfxml_ASroute_gw_dst;
273 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
274 || strlen(gw_dst) > 0,
275 "Some limits are null in the route between \"%s\" and \"%s\"",
277 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
281 * \brief Set the endponints for a bypassRoute
283 static void parse_S_bypassRoute_new_and_endpoints(void)
285 if (src != NULL && dst != NULL && link_list != NULL)
287 "Bypass Route between %s to %s can not be defined",
288 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
289 src = A_surfxml_bypassRoute_src;
290 dst = A_surfxml_bypassRoute_dst;
291 gw_src = A_surfxml_bypassRoute_gw_src;
292 gw_dst = A_surfxml_bypassRoute_gw_dst;
293 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
294 || strlen(gw_dst) > 0,
295 "Some limits are null in the route between \"%s\" and \"%s\"",
297 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
301 * \brief Set a new link on the actual list of link for a route or ASroute
303 static void parse_E_link_ctn_new_elem(char *link_id)
306 val = xbt_strdup(link_id);
307 xbt_dynar_push(link_list, &val);
311 * \brief Set a new link on the actual list of link for a route or ASroute from XML
314 static void parse_E_link_ctn_new_elem_XML(void)
316 if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
317 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
318 if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP)
319 parse_E_link_ctn_new_elem(bprintf("%s_UP",A_surfxml_link_ctn_id));
320 if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN)
321 parse_E_link_ctn_new_elem(bprintf("%s_DOWN",A_surfxml_link_ctn_id));
325 * \brief Set a new link on the actual list of link for a route or ASroute from lua
327 static void parse_E_link_c_ctn_new_elem_lua(char *link_id)
329 parse_E_link_ctn_new_elem(link_id);
333 * \brief Store the route by calling the set_route function of the current routing component
335 static void parse_E_route_store_route(void)
337 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
338 route->generic_route.link_list = link_list;
339 xbt_assert1(current_routing->set_route,
340 "no defined method \"set_route\" in \"%s\"",
341 current_routing->name);
342 (*(current_routing->set_route)) (current_routing, src, dst, route);
349 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
351 static void parse_E_ASroute_store_route(void)
353 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
354 e_route->generic_route.link_list = link_list;
355 e_route->src_gateway = xbt_strdup(gw_src);
356 e_route->dst_gateway = xbt_strdup(gw_dst);
357 xbt_assert1(current_routing->set_ASroute,
358 "no defined method \"set_ASroute\" in \"%s\"",
359 current_routing->name);
360 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
369 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
371 static void parse_E_bypassRoute_store_route(void)
373 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
374 e_route->generic_route.link_list = link_list;
375 e_route->src_gateway = xbt_strdup(gw_src);
376 e_route->dst_gateway = xbt_strdup(gw_dst);
377 xbt_assert1(current_routing->set_bypassroute,
378 "no defined method \"set_bypassroute\" in \"%s\"",
379 current_routing->name);
380 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
390 * \brief Make a new routing component
392 * make the new structure and
393 * set the parsing functions to allows parsing the part of the routing tree
395 static void parse_S_AS(char *AS_id, char *AS_routing)
397 routing_component_t new_routing;
398 model_type_t model = NULL;
399 char *wanted = AS_routing;
401 /* seach the routing model */
402 for (cpt = 0; routing_models[cpt].name; cpt++)
403 if (!strcmp(wanted, routing_models[cpt].name))
404 model = &routing_models[cpt];
405 /* if its not exist, error */
407 fprintf(stderr, "Routing model %s not found. Existing models:\n",
409 for (cpt = 0; routing_models[cpt].name; cpt++)
410 if (!strcmp(wanted, routing_models[cpt].name))
411 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
412 routing_models[cpt].desc);
416 /* make a new routing component */
417 new_routing = (routing_component_t) (*(model->create)) ();
418 new_routing->routing = model;
419 new_routing->hierarchy = SURF_ROUTING_NULL;
420 new_routing->name = xbt_strdup(AS_id);
421 new_routing->routing_sons = xbt_dict_new();
423 if (current_routing == NULL && global_routing->root == NULL) {
425 /* it is the first one */
426 new_routing->routing_father = NULL;
427 global_routing->root = new_routing;
429 } else if (current_routing != NULL && global_routing->root != NULL) {
431 xbt_assert1(!xbt_dict_get_or_null
432 (current_routing->routing_sons, AS_id),
433 "The AS \"%s\" already exist", AS_id);
434 /* it is a part of the tree */
435 new_routing->routing_father = current_routing;
436 /* set the father behavior */
437 if (current_routing->hierarchy == SURF_ROUTING_NULL)
438 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
439 /* add to the sons dictionary */
440 xbt_dict_set(current_routing->routing_sons, AS_id,
441 (void *) new_routing, NULL);
442 /* add to the father element list */
443 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
444 /* unload the prev parse rules */
445 (*(current_routing->routing->unload)) ();
448 THROW0(arg_error, 0, "All defined components must be belong to a AS");
450 /* set the new parse rules */
451 (*(new_routing->routing->load)) ();
452 /* set the new current component of the tree */
453 current_routing = new_routing;
457 * Detect the routing model type of the routing component from XML platforms
459 static void parse_S_AS_XML(void)
461 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
465 * define the routing model type of routing component from lua script
467 static void parse_S_AS_lua(char *id, char *mode)
469 parse_S_AS(id, mode);
474 * \brief Finish the creation of a new routing component
476 * When you finish to read the routing component, other structures must be created.
477 * the "end" method allow to do that for any routing model type
479 static void parse_E_AS(char *AS_id)
482 if (current_routing == NULL) {
483 THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id);
485 network_element_info_t info = NULL;
486 xbt_assert1(!xbt_dict_get_or_null
487 (global_routing->where_network_elements,
488 current_routing->name), "The AS \"%s\" already exist",
489 current_routing->name);
490 info = xbt_new0(s_network_element_info_t, 1);
491 info->rc_component = current_routing->routing_father;
492 info->rc_type = SURF_NETWORK_ELEMENT_AS;
493 xbt_dict_set(global_routing->where_network_elements,
494 current_routing->name, info, NULL);
495 (*(current_routing->routing->unload)) ();
496 (*(current_routing->routing->end)) ();
497 current_routing = current_routing->routing_father;
498 if (current_routing != NULL)
499 (*(current_routing->routing->load)) ();
504 * \brief Finish the creation of a new routing component from XML
506 static void parse_E_AS_XML(void)
508 parse_E_AS(A_surfxml_AS_id);
512 * \brief Finish the creation of a new routing component from lua
514 static void parse_E_AS_lua(char *id)
519 /* Aux Business methods */
522 * \brief Get the AS father and the first elements of the chain
524 * \param src the source host name
525 * \param dst the destination host name
527 * Get the common father of the to processing units, and the first different
528 * father in the chain
530 static xbt_dynar_t elements_father(const char *src, const char *dst)
533 xbt_assert0(src && dst, "bad parameters for \"elements_father\" method");
535 xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
537 routing_component_t src_as, dst_as;
538 int index_src, index_dst, index_father_src, index_father_dst;
539 xbt_dynar_t path_src = NULL;
540 xbt_dynar_t path_dst = NULL;
541 routing_component_t current = NULL;
542 routing_component_t *current_src = NULL;
543 routing_component_t *current_dst = NULL;
544 routing_component_t *father = NULL;
546 /* (1) find the as where the src and dst are located */
547 src_as = ((network_element_info_t)
548 xbt_dict_get_or_null(global_routing->where_network_elements,
550 dst_as = ((network_element_info_t)
551 xbt_dict_get_or_null(global_routing->where_network_elements,
555 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
558 /* (2) find the path to the root routing component */
559 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
561 while (current != NULL) {
562 xbt_dynar_push(path_src, ¤t);
563 current = current->routing_father;
565 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
567 while (current != NULL) {
568 xbt_dynar_push(path_dst, ¤t);
569 current = current->routing_father;
572 /* (3) find the common father */
573 index_src = (path_src->used) - 1;
574 index_dst = (path_dst->used) - 1;
575 current_src = xbt_dynar_get_ptr(path_src, index_src);
576 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
577 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
578 current_src = xbt_dynar_get_ptr(path_src, index_src);
579 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
585 current_src = xbt_dynar_get_ptr(path_src, index_src);
586 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
588 /* (4) they are not in the same routing component, make the path */
589 index_father_src = index_src + 1;
590 index_father_dst = index_dst + 1;
592 if (*current_src == *current_dst)
593 father = current_src;
595 father = xbt_dynar_get_ptr(path_src, index_father_src);
597 /* (5) result generation */
598 xbt_dynar_push(result, father); /* first same the father of src and dst */
599 xbt_dynar_push(result, current_src); /* second the first different father of src */
600 xbt_dynar_push(result, current_dst); /* three the first different father of dst */
602 xbt_dynar_free(&path_src);
603 xbt_dynar_free(&path_dst);
608 /* Global Business methods */
611 * \brief Recursive function for get_route
613 * \param src the source host name
614 * \param dst the destination host name
616 * This fuction is call by "get_route". It allow to walk through the
617 * routing components tree.
619 static route_extended_t _get_route(const char *src, const char *dst)
623 unsigned int cpt = 0;
625 DEBUG2("Solve route \"%s\" to \"%s\"", src, dst);
627 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
629 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
632 xbt_dynar_t elem_father_list = elements_father(src, dst);
634 routing_component_t common_father =
635 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
636 routing_component_t src_father =
637 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
638 routing_component_t dst_father =
639 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
641 e_route = xbt_new0(s_route_extended_t, 1);
642 e_route->src_gateway = NULL;
643 e_route->dst_gateway = NULL;
644 e_route->generic_route.link_list =
645 xbt_dynar_new(global_routing->size_of_link, NULL);
647 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
649 if (strcmp(src, dst)) {
651 (*(common_father->get_route)) (common_father, src, dst);
652 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
654 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
655 xbt_dynar_push(e_route->generic_route.link_list, &link);
657 generic_free_extended_route(e_route_cnt);
660 } else { /* SURF_ROUTING_RECURSIVE */
662 route_extended_t e_route_bypass = NULL;
664 if (common_father->get_bypass_route)
666 (*(common_father->get_bypass_route)) (common_father, src, dst);
669 e_route_cnt = e_route_bypass;
672 (*(common_father->get_route)) (common_father, src_father->name,
675 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
676 src_father->name, dst_father->name);
678 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
679 (e_route_cnt->dst_gateway == NULL),
680 "bad gateway for route between \"%s\" and \"%s\"", src,
683 if (src != e_route_cnt->src_gateway) {
684 e_route_src = _get_route(src, e_route_cnt->src_gateway);
685 xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
686 e_route_cnt->src_gateway);
687 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
688 xbt_dynar_push(e_route->generic_route.link_list, &link);
692 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
693 xbt_dynar_push(e_route->generic_route.link_list, &link);
696 if (e_route_cnt->dst_gateway != dst) {
697 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
698 xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
699 e_route_cnt->dst_gateway, dst);
700 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
701 xbt_dynar_push(e_route->generic_route.link_list, &link);
705 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
706 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
708 generic_free_extended_route(e_route_src);
709 generic_free_extended_route(e_route_cnt);
710 generic_free_extended_route(e_route_dst);
713 xbt_dynar_free(&elem_father_list);
719 * \brief Generic method: find a route between hosts
721 * \param src the source host name
722 * \param dst the destination host name
724 * walk through the routing components tree and find a route between hosts
725 * by calling the differents "get_route" functions in each routing component.
726 * No need to free the returned dynar. It will be freed at the next call.
728 static xbt_dynar_t get_route(const char *src, const char *dst)
731 route_extended_t e_route;
732 xbt_dynar_t elem_father_list = elements_father(src, dst);
733 routing_component_t common_father =
734 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
736 if (strcmp(src, dst))
737 e_route = _get_route(src, dst);
739 e_route = (*(common_father->get_route)) (common_father, src, dst);
741 xbt_assert2(e_route, "no route between \"%s\" and \"%s\"", src, dst);
743 if (global_routing->last_route)
744 xbt_dynar_free(&(global_routing->last_route));
745 global_routing->last_route = e_route->generic_route.link_list;
747 if (e_route->src_gateway)
748 xbt_free(e_route->src_gateway);
749 if (e_route->dst_gateway)
750 xbt_free(e_route->dst_gateway);
753 xbt_dynar_free(&elem_father_list);
755 if (xbt_dynar_length(global_routing->last_route) == 0)
758 return global_routing->last_route;
762 * \brief Generic method: find a route between hosts
764 * \param src the source host name
765 * \param dst the destination host name
767 * walk through the routing components tree and find a route between hosts
768 * by calling the differents "get_route" functions in each routing component.
769 * Leaves the caller the responsability to clean the returned dynar.
771 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
773 xbt_dynar_t d = get_route(src,dst);
774 global_routing->last_route = NULL;
779 * \brief Recursive function for finalize
781 * \param rc the source host name
783 * This fuction is call by "finalize". It allow to finalize the
784 * AS or routing components. It delete all the structures.
786 static void _finalize(routing_component_t rc)
789 xbt_dict_cursor_t cursor = NULL;
791 routing_component_t elem;
792 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
795 xbt_dict_t tmp_sons = rc->routing_sons;
796 char *tmp_name = rc->name;
797 xbt_dict_free(&tmp_sons);
799 xbt_assert1(rc->finalize, "no defined method \"finalize\" in \"%s\"",
800 current_routing->name);
801 (*(rc->finalize)) (rc);
806 * \brief Generic method: delete all the routing structures
808 * walk through the routing components tree and delete the structures
809 * by calling the differents "finalize" functions in each routing component
811 static void finalize(void)
813 /* delete recursibly all the tree */
814 _finalize(global_routing->root);
815 /* delete "where" dict */
816 xbt_dict_free(&(global_routing->where_network_elements));
817 /* delete last_route */
818 xbt_dynar_free(&(global_routing->last_route));
819 /* delete global routing structure */
820 xbt_free(global_routing);
823 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
825 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
827 //adding my one link routes
830 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
832 xbt_dynar_foreach(onelink_mine, cpt, link) {
833 xbt_dynar_push(ret, &link);
838 xbt_dict_cursor_t cursor = NULL;
839 routing_component_t rc_child;
840 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
841 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
843 xbt_dynar_foreach(onelink_child, cpt, link) {
844 xbt_dynar_push(ret, &link);
851 static xbt_dynar_t get_onelink_routes(void)
853 return recursive_get_onelink_routes(global_routing->root);
856 static e_surf_network_element_type_t get_network_element_type(const char
859 network_element_info_t rc = NULL;
860 rc = xbt_dict_get(global_routing->where_network_elements, name);
865 * \brief Generic method: create the global routing schema
867 * Make a global routing structure and set all the parsing functions.
869 void routing_model_create(size_t size_of_links, void *loopback)
872 /* config the uniq global routing */
873 global_routing = xbt_new0(s_routing_global_t, 1);
874 global_routing->where_network_elements = xbt_dict_new();
875 global_routing->root = NULL;
876 global_routing->get_route = get_route;
877 global_routing->get_route_no_cleanup = get_route_no_cleanup;
878 global_routing->get_onelink_routes = get_onelink_routes;
879 global_routing->get_network_element_type = get_network_element_type;
880 global_routing->finalize = finalize;
881 global_routing->loopback = loopback;
882 global_routing->size_of_link = size_of_links;
883 global_routing->last_route = NULL;
885 /* no current routing at moment */
886 current_routing = NULL;
888 /* parse generic elements */
889 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
890 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
892 surfxml_add_callback(STag_surfxml_route_cb_list,
893 &parse_S_route_new_and_endpoints_XML);
894 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
895 &parse_S_ASroute_new_and_endpoints);
896 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
897 &parse_S_bypassRoute_new_and_endpoints);
899 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
900 &parse_E_link_ctn_new_elem_XML);
902 surfxml_add_callback(ETag_surfxml_route_cb_list,
903 &parse_E_route_store_route);
904 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
905 &parse_E_ASroute_store_route);
906 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
907 &parse_E_bypassRoute_store_route);
909 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
910 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
912 surfxml_add_callback(STag_surfxml_cluster_cb_list,
913 &routing_parse_Scluster);
915 surfxml_add_callback(STag_surfxml_config_cb_list,
916 &routing_parse_Sconfig);
917 surfxml_add_callback(ETag_surfxml_config_cb_list,
918 &routing_parse_Econfig);
921 /* ************************************************************************** */
922 /* *************************** FULL ROUTING ********************************* */
924 #define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
926 /* Routing model structure */
929 s_routing_component_t generic_routing;
930 route_extended_t *routing_table;
931 } s_routing_component_full_t, *routing_component_full_t;
933 /* Business methods */
934 static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
936 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
938 routing_component_full_t routing = (routing_component_full_t) rc;
939 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
940 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
941 char *k1, *d1, *k2, *d2;
942 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
943 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
944 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k1);
945 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k2);
948 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
950 route_extended_t route = TO_ROUTE_FULL(*src_id, *dst_id);
952 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
954 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
956 onelink_t onelink = xbt_new0(s_onelink_t, 1);
957 onelink->link_ptr = link;
958 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
959 onelink->src = xbt_strdup(k1);
960 onelink->dst = xbt_strdup(k2);
961 } else if (routing->generic_routing.hierarchy ==
962 SURF_ROUTING_RECURSIVE) {
963 onelink->src = xbt_strdup(route->src_gateway);
964 onelink->dst = xbt_strdup(route->dst_gateway);
966 xbt_dynar_push(ret, &onelink);
974 static route_extended_t full_get_route(routing_component_t rc,
975 const char *src, const char *dst)
977 xbt_assert1(rc && src
979 "Invalid params for \"get_route\" function at AS \"%s\"",
983 routing_component_full_t routing = (routing_component_full_t) rc;
984 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
986 generic_src_dst_check(rc, src, dst);
987 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
988 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
991 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
994 route_extended_t e_route = NULL;
995 route_extended_t new_e_route = NULL;
997 unsigned int cpt = 0;
999 e_route = TO_ROUTE_FULL(*src_id, *dst_id);
1002 new_e_route = xbt_new0(s_route_extended_t, 1);
1003 new_e_route->src_gateway = xbt_strdup(e_route->src_gateway);
1004 new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway);
1005 new_e_route->generic_route.link_list =
1006 xbt_dynar_new(global_routing->size_of_link, NULL);
1007 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
1008 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1014 static void full_finalize(routing_component_t rc)
1016 routing_component_full_t routing = (routing_component_full_t) rc;
1017 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1020 /* Delete routing table */
1021 for (i = 0; i < table_size; i++)
1022 for (j = 0; j < table_size; j++)
1023 generic_free_extended_route(TO_ROUTE_FULL(i, j));
1024 xbt_free(routing->routing_table);
1025 /* Delete bypass dict */
1026 xbt_dict_free(&rc->bypassRoutes);
1027 /* Delete index dict */
1028 xbt_dict_free(&rc->to_index);
1029 /* Delete structure */
1034 /* Creation routing model functions */
1036 static void *model_full_create(void)
1038 routing_component_full_t new_component =
1039 xbt_new0(s_routing_component_full_t, 1);
1040 new_component->generic_routing.set_processing_unit =
1041 generic_set_processing_unit;
1042 new_component->generic_routing.set_autonomous_system =
1043 generic_set_autonomous_system;
1044 new_component->generic_routing.set_route = model_full_set_route;
1045 new_component->generic_routing.set_ASroute = model_full_set_route;
1046 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1047 new_component->generic_routing.get_route = full_get_route;
1048 new_component->generic_routing.get_onelink_routes =
1049 full_get_onelink_routes;
1050 new_component->generic_routing.get_bypass_route =
1051 generic_get_bypassroute;
1052 new_component->generic_routing.finalize = full_finalize;
1053 new_component->generic_routing.to_index = xbt_dict_new();
1054 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1055 return new_component;
1058 static void model_full_load(void)
1060 /* use "surfxml_add_callback" to add a parse function call */
1063 static void model_full_unload(void)
1065 /* use "surfxml_del_callback" to remove a parse function call */
1068 static void model_full_end(void)
1071 route_extended_t e_route;
1073 /* set utils vars */
1074 routing_component_full_t routing =
1075 ((routing_component_full_t) current_routing);
1076 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1078 /* Create table if necessary */
1079 if(!routing->routing_table)
1080 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1082 /* Add the loopback if needed */
1083 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1084 for (i = 0; i < table_size; i++) {
1085 e_route = TO_ROUTE_FULL(i, i);
1087 e_route = xbt_new0(s_route_extended_t, 1);
1088 e_route->src_gateway = NULL;
1089 e_route->dst_gateway = NULL;
1090 e_route->generic_route.link_list =
1091 xbt_dynar_new(global_routing->size_of_link, NULL);
1092 xbt_dynar_push(e_route->generic_route.link_list,
1093 &global_routing->loopback);
1094 TO_ROUTE_FULL(i, i) = e_route;
1100 static void model_full_set_route(routing_component_t rc, const char *src,
1101 const char *dst, name_route_extended_t route)
1103 int *src_id, *dst_id;
1104 src_id = xbt_dict_get_or_null(rc->to_index, src);
1105 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1106 routing_component_full_t routing = ((routing_component_full_t) rc);
1107 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1110 && dst_id, "Network elements %s or %s not found", src, dst);
1112 xbt_assert2(xbt_dynar_length(route->generic_route.link_list) > 0,
1113 "Invalid count of links, must be greater than zero (%s,%s)",
1116 if(!routing->routing_table)
1117 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1119 if(TO_ROUTE_FULL(*src_id, *dst_id))
1123 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1124 xbt_dynar_foreach(route->generic_route.link_list,i,link_name)
1126 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1127 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1128 xbt_dynar_push(link_route_to_test,&link);
1130 xbt_assert2(!xbt_dynar_compare(
1131 (void*)TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list,
1132 (void*)link_route_to_test,
1133 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1134 "The route between \"%s\" and \"%s\" already exist", src,dst);
1135 xbt_free(link_route_to_test);
1139 if(!route->dst_gateway && !route->src_gateway)
1140 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1142 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1143 route->src_gateway, dst, route->dst_gateway);
1144 TO_ROUTE_FULL(*src_id, *dst_id) = generic_new_extended_route(rc->hierarchy,route,1);
1145 xbt_dynar_shrink(TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list, 0);
1148 if( A_surfxml_route_symetrical == A_surfxml_route_symetrical_YES
1149 || A_surfxml_ASroute_symetrical == A_surfxml_ASroute_symetrical_YES )
1151 if(route->dst_gateway && route->src_gateway)
1153 char * gw_src = bprintf("%s",route->src_gateway);
1154 char * gw_dst = bprintf("%s",route->dst_gateway);
1155 route->src_gateway = bprintf("%s",gw_dst);
1156 route->dst_gateway = bprintf("%s",gw_src);
1158 if(TO_ROUTE_FULL(*dst_id, *src_id))
1162 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1163 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1165 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1166 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1167 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1168 xbt_dynar_push(link_route_to_test,&link);
1170 xbt_assert2(!xbt_dynar_compare(
1171 (void*)TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list,
1172 (void*)link_route_to_test,
1173 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1174 "The route between \"%s\" and \"%s\" already exist", src,dst);
1175 xbt_free(link_route_to_test);
1179 if(!route->dst_gateway && !route->src_gateway)
1180 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1182 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1183 route->src_gateway, src, route->dst_gateway);
1184 TO_ROUTE_FULL(*dst_id, *src_id) = generic_new_extended_route(rc->hierarchy,route,0);
1185 xbt_dynar_shrink(TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list, 0);
1191 /* ************************************************************************** */
1192 /* *************************** FLOYD ROUTING ******************************** */
1194 #define TO_FLOYD_COST(i,j) (routing->cost_table)[(i)+(j)*table_size]
1195 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
1196 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
1198 /* Routing model structure */
1201 s_routing_component_t generic_routing;
1202 /* vars for calculate the floyd algorith. */
1203 int *predecessor_table;
1205 route_extended_t *link_table; /* char* -> int* */
1206 } s_routing_component_floyd_t, *routing_component_floyd_t;
1208 static route_extended_t floyd_get_route(routing_component_t rc,
1209 const char *src, const char *dst);
1211 /* Business methods */
1212 static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
1214 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1216 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1217 //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1218 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1219 char *k1, *d1, *k2, *d2;
1220 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1221 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1222 route_extended_t route = floyd_get_route(rc, k1, k2);
1224 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1226 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1228 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1229 onelink->link_ptr = link;
1230 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1231 onelink->src = xbt_strdup(k1);
1232 onelink->dst = xbt_strdup(k2);
1233 } else if (routing->generic_routing.hierarchy ==
1234 SURF_ROUTING_RECURSIVE) {
1235 onelink->src = xbt_strdup(route->src_gateway);
1236 onelink->dst = xbt_strdup(route->dst_gateway);
1238 xbt_dynar_push(ret, &onelink);
1246 static route_extended_t floyd_get_route(routing_component_t rc,
1247 const char *src, const char *dst)
1249 xbt_assert1(rc && src
1251 "Invalid params for \"get_route\" function at AS \"%s\"",
1254 /* set utils vars */
1255 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1256 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1258 generic_src_dst_check(rc, src, dst);
1259 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1260 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1263 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1266 /* create a result route */
1267 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1268 new_e_route->generic_route.link_list =
1269 xbt_dynar_new(global_routing->size_of_link, NULL);
1270 new_e_route->src_gateway = NULL;
1271 new_e_route->dst_gateway = NULL;
1276 char *gw_src = NULL, *gw_dst =
1277 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1284 pred = TO_FLOYD_PRED(*src_id, pred);
1285 if (pred == -1) /* if no pred in route -> no route to host */
1287 xbt_assert2(TO_FLOYD_LINK(pred, prev_pred),
1288 "Invalid link for the route between \"%s\" or \"%s\"", src,
1291 prev_gw_src = gw_src;
1292 prev_gw_dst = gw_dst;
1294 route_extended_t e_route = TO_FLOYD_LINK(pred, prev_pred);
1295 gw_src = e_route->src_gateway;
1296 gw_dst = e_route->dst_gateway;
1301 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && !first
1302 && strcmp(gw_dst, prev_gw_src)) {
1303 xbt_dynar_t e_route_as_to_as =
1304 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1305 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1306 gw_dst, prev_gw_src);
1307 links = e_route_as_to_as;
1309 xbt_dynar_foreach(links, cpt, link) {
1310 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1316 links = e_route->generic_route.link_list;
1317 xbt_dynar_foreach(links, cpt, link) {
1318 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1322 } while (pred != *src_id);
1323 xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")",
1324 *src_id, *dst_id, src, dst);
1326 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1327 new_e_route->src_gateway = xbt_strdup(gw_src);
1328 new_e_route->dst_gateway = xbt_strdup(first_gw);
1334 static void floyd_finalize(routing_component_t rc)
1336 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1340 table_size = xbt_dict_length(routing->generic_routing.to_index);
1341 /* Delete link_table */
1342 for (i = 0; i < table_size; i++)
1343 for (j = 0; j < table_size; j++)
1344 generic_free_extended_route(TO_FLOYD_LINK(i, j));
1345 xbt_free(routing->link_table);
1346 /* Delete bypass dict */
1347 xbt_dict_free(&routing->generic_routing.bypassRoutes);
1348 /* Delete index dict */
1349 xbt_dict_free(&(routing->generic_routing.to_index));
1350 /* Delete dictionary index dict, predecessor and links table */
1351 xbt_free(routing->predecessor_table);
1352 /* Delete structure */
1357 static void *model_floyd_create(void)
1359 routing_component_floyd_t new_component =
1360 xbt_new0(s_routing_component_floyd_t, 1);
1361 new_component->generic_routing.set_processing_unit =
1362 generic_set_processing_unit;
1363 new_component->generic_routing.set_autonomous_system =
1364 generic_set_autonomous_system;
1365 new_component->generic_routing.set_route = model_floyd_set_route;
1366 new_component->generic_routing.set_ASroute = model_floyd_set_route;
1367 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1368 new_component->generic_routing.get_route = floyd_get_route;
1369 new_component->generic_routing.get_onelink_routes =
1370 floyd_get_onelink_routes;
1371 new_component->generic_routing.get_bypass_route =
1372 generic_get_bypassroute;
1373 new_component->generic_routing.finalize = floyd_finalize;
1374 new_component->generic_routing.to_index = xbt_dict_new();
1375 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1376 new_component->generic_routing.parse_routes = xbt_dict_new();
1377 return new_component;
1380 static void model_floyd_load(void)
1382 /* use "surfxml_add_callback" to add a parse function call */
1385 static void model_floyd_unload(void)
1387 /* use "surfxml_del_callback" to remove a parse function call */
1390 static void model_floyd_end(void)
1393 routing_component_floyd_t routing =
1394 ((routing_component_floyd_t) current_routing);
1396 unsigned int i, j, a, b, c;
1398 /* set the size of table routing */
1399 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1401 if(!routing->link_table)
1403 /* Create Cost, Predecessor and Link tables */
1404 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1405 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1406 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1408 /* Initialize costs and predecessors */
1409 for (i = 0; i < table_size; i++)
1410 for (j = 0; j < table_size; j++) {
1411 TO_FLOYD_COST(i, j) = DBL_MAX;
1412 TO_FLOYD_PRED(i, j) = -1;
1413 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1417 /* Add the loopback if needed */
1418 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1419 for (i = 0; i < table_size; i++) {
1420 route_extended_t e_route = TO_FLOYD_LINK(i, i);
1422 e_route = xbt_new0(s_route_extended_t, 1);
1423 e_route->src_gateway = NULL;
1424 e_route->dst_gateway = NULL;
1425 e_route->generic_route.link_list =
1426 xbt_dynar_new(global_routing->size_of_link, NULL);
1427 xbt_dynar_push(e_route->generic_route.link_list,
1428 &global_routing->loopback);
1429 TO_FLOYD_LINK(i, i) = e_route;
1430 TO_FLOYD_PRED(i, i) = i;
1431 TO_FLOYD_COST(i, i) = 1;
1435 /* Calculate path costs */
1436 for (c = 0; c < table_size; c++) {
1437 for (a = 0; a < table_size; a++) {
1438 for (b = 0; b < table_size; b++) {
1439 if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
1440 if (TO_FLOYD_COST(a, b) == DBL_MAX ||
1441 (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
1442 TO_FLOYD_COST(a, b))) {
1443 TO_FLOYD_COST(a, b) =
1444 TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
1445 TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
1453 static void model_floyd_set_route(routing_component_t rc, const char *src,
1454 const char *dst, name_route_extended_t route)
1456 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1458 /* set the size of table routing */
1459 size_t table_size = xbt_dict_length(rc->to_index);
1460 int *src_id, *dst_id;
1463 src_id = xbt_dict_get_or_null(rc->to_index, src);
1464 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1466 if(!routing->link_table)
1468 /* Create Cost, Predecessor and Link tables */
1469 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1470 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1471 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1473 /* Initialize costs and predecessors */
1474 for (i = 0; i < table_size; i++)
1475 for (j = 0; j < table_size; j++) {
1476 TO_FLOYD_COST(i, j) = DBL_MAX;
1477 TO_FLOYD_PRED(i, j) = -1;
1478 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1482 if(TO_FLOYD_LINK(*src_id, *dst_id))
1484 if(!route->dst_gateway && !route->src_gateway)
1485 DEBUG2("See Route from \"%s\" to \"%s\"", src, dst);
1487 DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1488 route->src_gateway, dst, route->dst_gateway);
1491 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1492 xbt_dynar_foreach(route->generic_route.link_list,cpt,link_name)
1494 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1495 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1496 xbt_dynar_push(link_route_to_test,&link);
1498 xbt_assert2(!xbt_dynar_compare(
1499 (void*)TO_FLOYD_LINK(*src_id, *dst_id)->generic_route.link_list,
1500 (void*)link_route_to_test,
1501 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1502 "The route between \"%s\" and \"%s\" already exist", src,dst);
1503 xbt_free(link_route_to_test);
1507 if(!route->dst_gateway && !route->src_gateway)
1508 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1510 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1511 route->src_gateway, dst, route->dst_gateway);
1513 TO_FLOYD_LINK(*src_id, *dst_id) =
1514 generic_new_extended_route(rc->hierarchy, route, 1);
1515 TO_FLOYD_PRED(*src_id, *dst_id) = *src_id;
1516 TO_FLOYD_COST(*src_id, *dst_id) =
1517 ((TO_FLOYD_LINK(*src_id, *dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1520 if( A_surfxml_route_symetrical == A_surfxml_route_symetrical_YES
1521 || A_surfxml_ASroute_symetrical == A_surfxml_ASroute_symetrical_YES )
1523 if(TO_FLOYD_LINK(*dst_id, *src_id))
1525 if(!route->dst_gateway && !route->src_gateway)
1526 DEBUG2("See Route from \"%s\" to \"%s\"", dst, src);
1528 DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1529 route->src_gateway, src, route->dst_gateway);
1532 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1533 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1535 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1536 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1537 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1538 xbt_dynar_push(link_route_to_test,&link);
1540 xbt_assert2(!xbt_dynar_compare(
1541 (void*)TO_FLOYD_LINK(*dst_id, *src_id)->generic_route.link_list,
1542 (void*)link_route_to_test,
1543 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1544 "The route between \"%s\" and \"%s\" already exist", src,dst);
1545 xbt_free(link_route_to_test);
1549 if(route->dst_gateway && route->src_gateway)
1551 char * gw_src = bprintf("%s",route->src_gateway);
1552 char * gw_dst = bprintf("%s",route->dst_gateway);
1553 route->src_gateway = bprintf("%s",gw_dst);
1554 route->dst_gateway = bprintf("%s",gw_src);
1557 if(!route->dst_gateway && !route->src_gateway)
1558 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1560 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1561 route->src_gateway, src, route->dst_gateway);
1563 TO_FLOYD_LINK(*dst_id, *src_id) =
1564 generic_new_extended_route(rc->hierarchy, route, 0);
1565 TO_FLOYD_PRED(*dst_id, *src_id) = *dst_id;
1566 TO_FLOYD_COST(*dst_id, *src_id) =
1567 ((TO_FLOYD_LINK(*dst_id, *src_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1572 /* ************************************************************************** */
1573 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1576 s_routing_component_t generic_routing;
1577 xbt_graph_t route_graph; /* xbt_graph */
1578 xbt_dict_t graph_node_map; /* map */
1579 xbt_dict_t route_cache; /* use in cache mode */
1581 } s_routing_component_dijkstra_t, *routing_component_dijkstra_t;
1584 typedef struct graph_node_data {
1586 int graph_id; /* used for caching internal graph id's */
1587 } s_graph_node_data_t, *graph_node_data_t;
1589 typedef struct graph_node_map_element {
1591 } s_graph_node_map_element_t, *graph_node_map_element_t;
1593 typedef struct route_cache_element {
1596 } s_route_cache_element_t, *route_cache_element_t;
1598 /* Free functions */
1600 static void route_cache_elem_free(void *e)
1602 route_cache_element_t elm = (route_cache_element_t) e;
1604 xbt_free(elm->pred_arr);
1609 static void graph_node_map_elem_free(void *e)
1611 graph_node_map_element_t elm = (graph_node_map_element_t) e;
1617 static void graph_edge_data_free(void *e)
1619 route_extended_t e_route = (route_extended_t) e;
1621 xbt_dynar_free(&(e_route->generic_route.link_list));
1622 if (e_route->src_gateway)
1623 xbt_free(e_route->src_gateway);
1624 if (e_route->dst_gateway)
1625 xbt_free(e_route->dst_gateway);
1630 /* Utility functions */
1632 static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc,
1633 int id, int graph_id)
1635 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1636 xbt_node_t node = NULL;
1637 graph_node_data_t data = NULL;
1638 graph_node_map_element_t elm = NULL;
1640 data = xbt_new0(struct graph_node_data, 1);
1642 data->graph_id = graph_id;
1643 node = xbt_graph_new_node(routing->route_graph, data);
1645 elm = xbt_new0(struct graph_node_map_element, 1);
1647 xbt_dict_set_ext(routing->graph_node_map, (char *) (&id), sizeof(int),
1648 (xbt_set_elm_t) elm, &graph_node_map_elem_free);
1653 static graph_node_map_element_t
1654 graph_node_map_search(routing_component_dijkstra_t rc, int id)
1656 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1657 graph_node_map_element_t elm = (graph_node_map_element_t)
1658 xbt_dict_get_or_null_ext(routing->graph_node_map,
1666 static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id,
1667 int dst_id, route_extended_t e_route)
1669 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1671 xbt_node_t src = NULL;
1672 xbt_node_t dst = NULL;
1673 graph_node_map_element_t src_elm = (graph_node_map_element_t)
1674 xbt_dict_get_or_null_ext(routing->graph_node_map,
1677 graph_node_map_element_t dst_elm = (graph_node_map_element_t)
1678 xbt_dict_get_or_null_ext(routing->graph_node_map,
1683 src = src_elm->node;
1686 dst = dst_elm->node;
1688 /* add nodes if they don't exist in the graph */
1689 if (src_id == dst_id && src == NULL && dst == NULL) {
1690 src = route_graph_new_node(rc, src_id, -1);
1694 src = route_graph_new_node(rc, src_id, -1);
1697 dst = route_graph_new_node(rc, dst_id, -1);
1701 /* add link as edge to graph */
1702 xbt_graph_new_edge(routing->route_graph, src, dst, e_route);
1705 static void add_loopback_dijkstra(routing_component_dijkstra_t rc)
1707 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1709 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1711 xbt_node_t node = NULL;
1712 unsigned int cursor2;
1713 xbt_dynar_foreach(nodes, cursor2, node) {
1714 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1715 xbt_edge_t edge = NULL;
1716 unsigned int cursor;
1719 xbt_dynar_foreach(out_edges, cursor, edge) {
1720 xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1721 if (other_node == node) {
1728 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
1729 e_route->src_gateway = NULL;
1730 e_route->dst_gateway = NULL;
1731 e_route->generic_route.link_list =
1732 xbt_dynar_new(global_routing->size_of_link, NULL);
1733 xbt_dynar_push(e_route->generic_route.link_list,
1734 &global_routing->loopback);
1735 xbt_graph_new_edge(routing->route_graph, node, node, e_route);
1740 /* Business methods */
1741 static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
1743 xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
1746 static route_extended_t dijkstra_get_route(routing_component_t rc,
1750 xbt_assert1(rc && src
1752 "Invalid params for \"get_route\" function at AS \"%s\"",
1755 /* set utils vars */
1756 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1758 generic_src_dst_check(rc, src, dst);
1759 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1760 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1763 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1766 /* create a result route */
1767 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1768 new_e_route->generic_route.link_list =
1769 xbt_dynar_new(global_routing->size_of_link, NULL);
1770 new_e_route->src_gateway = NULL;
1771 new_e_route->dst_gateway = NULL;
1773 int *pred_arr = NULL;
1774 int src_node_id = 0;
1775 int dst_node_id = 0;
1778 route_extended_t e_route;
1782 xbt_dynar_t links = NULL;
1783 route_cache_element_t elm = NULL;
1784 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1786 /* Use the graph_node id mapping set to quickly find the nodes */
1787 graph_node_map_element_t src_elm =
1788 graph_node_map_search(routing, *src_id);
1789 graph_node_map_element_t dst_elm =
1790 graph_node_map_search(routing, *dst_id);
1791 xbt_assert2(src_elm != NULL
1792 && dst_elm != NULL, "src %d or dst %d does not exist",
1794 src_node_id = ((graph_node_data_t)
1795 xbt_graph_node_get_data(src_elm->node))->graph_id;
1796 dst_node_id = ((graph_node_data_t)
1797 xbt_graph_node_get_data(dst_elm->node))->graph_id;
1799 /* if the src and dst are the same *//* fixed, missing in the previous version */
1800 if (src_node_id == dst_node_id) {
1802 xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
1803 xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
1805 xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v);
1807 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
1810 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
1812 links = e_route->generic_route.link_list;
1813 xbt_dynar_foreach(links, cpt, link) {
1814 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1820 if (routing->cached) {
1821 /*check if there is a cached predecessor list avail */
1822 elm = (route_cache_element_t)
1823 xbt_dict_get_or_null_ext(routing->route_cache, (char *) (&src_id),
1827 if (elm) { /* cached mode and cache hit */
1828 pred_arr = elm->pred_arr;
1829 } else { /* not cached mode or cache miss */
1830 double *cost_arr = NULL;
1831 xbt_heap_t pqueue = NULL;
1834 int nr_nodes = xbt_dynar_length(nodes);
1835 cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
1836 pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
1837 pqueue = xbt_heap_new(nr_nodes, xbt_free);
1840 cost_arr[src_node_id] = 0.0;
1842 for (i = 0; i < nr_nodes; i++) {
1843 if (i != src_node_id) {
1844 cost_arr[i] = DBL_MAX;
1849 /* initialize priority queue */
1850 nodeid = xbt_new0(int, 1);
1852 xbt_heap_push(pqueue, nodeid, cost_arr[i]);
1856 /* apply dijkstra using the indexes from the graph's node array */
1857 while (xbt_heap_size(pqueue) > 0) {
1858 int *v_id = xbt_heap_pop(pqueue);
1859 xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
1860 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
1861 xbt_edge_t edge = NULL;
1862 unsigned int cursor;
1864 xbt_dynar_foreach(out_edges, cursor, edge) {
1865 xbt_node_t u_node = xbt_graph_edge_get_target(edge);
1866 graph_node_data_t data = xbt_graph_node_get_data(u_node);
1867 int u_id = data->graph_id;
1868 route_extended_t tmp_e_route =
1869 (route_extended_t) xbt_graph_edge_get_data(edge);
1870 int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */
1872 if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
1873 pred_arr[u_id] = *v_id;
1874 cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
1875 nodeid = xbt_new0(int, 1);
1877 xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
1881 /* free item popped from pqueue */
1886 xbt_heap_free(pqueue);
1889 /* compose route path with links */
1890 char *gw_src = NULL, *gw_dst =
1891 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1893 for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
1894 xbt_node_t node_pred_v =
1895 xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
1896 xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
1898 xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
1900 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
1903 prev_gw_src = gw_src;
1904 prev_gw_dst = gw_dst;
1906 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
1907 gw_src = e_route->src_gateway;
1908 gw_dst = e_route->dst_gateway;
1910 if (v == dst_node_id)
1913 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
1914 && strcmp(gw_dst, prev_gw_src)) {
1915 xbt_dynar_t e_route_as_to_as =
1916 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1917 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1918 gw_dst, prev_gw_src);
1919 links = e_route_as_to_as;
1921 xbt_dynar_foreach(links, cpt, link) {
1922 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1928 links = e_route->generic_route.link_list;
1929 xbt_dynar_foreach(links, cpt, link) {
1930 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1935 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1936 new_e_route->src_gateway = xbt_strdup(gw_src);
1937 new_e_route->dst_gateway = xbt_strdup(first_gw);
1940 if (routing->cached && elm == NULL) {
1941 /* add to predecessor list of the current src-host to cache */
1942 elm = xbt_new0(struct route_cache_element, 1);
1943 elm->pred_arr = pred_arr;
1945 xbt_dict_set_ext(routing->route_cache, (char *) (&src_id), sizeof(int),
1946 (xbt_set_elm_t) elm, &route_cache_elem_free);
1949 if (!routing->cached)
1955 static void dijkstra_finalize(routing_component_t rc)
1957 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1960 xbt_graph_free_graph(routing->route_graph, &xbt_free,
1961 &graph_edge_data_free, &xbt_free);
1962 xbt_dict_free(&routing->graph_node_map);
1963 if (routing->cached)
1964 xbt_dict_free(&routing->route_cache);
1965 /* Delete bypass dict */
1966 xbt_dict_free(&routing->generic_routing.bypassRoutes);
1967 /* Delete index dict */
1968 xbt_dict_free(&(routing->generic_routing.to_index));
1969 /* Delete structure */
1974 /* Creation routing model functions */
1976 static void *model_dijkstra_both_create(int cached)
1978 routing_component_dijkstra_t new_component =
1979 xbt_new0(s_routing_component_dijkstra_t, 1);
1980 new_component->generic_routing.set_processing_unit =
1981 generic_set_processing_unit;
1982 new_component->generic_routing.set_autonomous_system =
1983 generic_set_autonomous_system;
1984 new_component->generic_routing.set_route = model_dijkstra_both_set_route;
1985 new_component->generic_routing.set_ASroute = NULL; //TODO
1986 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1987 new_component->generic_routing.get_route = dijkstra_get_route;
1988 new_component->generic_routing.get_onelink_routes =
1989 dijkstra_get_onelink_routes;
1990 new_component->generic_routing.get_bypass_route =
1991 generic_get_bypassroute;
1992 new_component->generic_routing.finalize = dijkstra_finalize;
1993 new_component->cached = cached;
1994 new_component->generic_routing.to_index = xbt_dict_new();
1995 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1996 new_component->generic_routing.parse_routes = xbt_dict_new();
1997 return new_component;
2000 static void *model_dijkstra_create(void)
2002 return model_dijkstra_both_create(0);
2005 static void *model_dijkstracache_create(void)
2007 return model_dijkstra_both_create(1);
2010 static void model_dijkstra_both_load(void)
2012 /* use "surfxml_add_callback" to add a parse function call */
2015 static void model_dijkstra_both_unload(void)
2017 /* use "surfxml_del_callback" to remove a parse function call */
2020 static void model_dijkstra_both_end(void)
2022 routing_component_dijkstra_t routing =
2023 (routing_component_dijkstra_t) current_routing;
2024 xbt_dict_cursor_t cursor = NULL;
2025 char *key, *data, *end;
2026 const char *sep = "#";
2028 xbt_node_t node = NULL;
2029 unsigned int cursor2;
2030 xbt_dynar_t nodes = NULL;
2034 /* Create the topology graph */
2035 routing->route_graph = xbt_graph_new_graph(1, NULL);
2036 routing->graph_node_map = xbt_dict_new();
2038 if (routing->cached)
2039 routing->route_cache = xbt_dict_new();
2041 /* Put the routes in position */
2042 xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
2043 keys = xbt_str_split_str(key, sep);
2044 src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10);
2045 dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10);
2046 route_extended_t e_route =
2047 generic_new_extended_route(current_routing->hierarchy, data, 0);
2048 route_new_dijkstra(routing, src_id, dst_id, e_route);
2049 xbt_dynar_free(&keys);
2052 /* delete the parse table */
2053 xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
2054 route = (route_t) data;
2055 xbt_dynar_free(&(route->link_list));
2059 /* delete parse dict */
2060 xbt_dict_free(&(routing->generic_routing.parse_routes));
2062 /* Add the loopback if needed */
2063 if (current_routing->hierarchy == SURF_ROUTING_BASE)
2064 add_loopback_dijkstra(routing);
2066 /* initialize graph indexes in nodes after graph has been built */
2067 nodes = xbt_graph_get_nodes(routing->route_graph);
2069 xbt_dynar_foreach(nodes, cursor2, node) {
2070 graph_node_data_t data = xbt_graph_node_get_data(node);
2071 data->graph_id = cursor2;
2075 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
2076 const char *dst, name_route_extended_t route)
2082 #ifdef HAVE_PCRE_LIB
2083 /* ************************************************** */
2084 /* ************** RULE-BASED ROUTING **************** */
2086 /* Routing model structure */
2089 s_routing_component_t generic_routing;
2090 xbt_dict_t dict_processing_units;
2091 xbt_dict_t dict_autonomous_systems;
2092 xbt_dynar_t list_route;
2093 xbt_dynar_t list_ASroute;
2094 } s_routing_component_rulebased_t, *routing_component_rulebased_t;
2096 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
2097 typedef struct s_rule_route_extended s_rule_route_extended_t,
2098 *rule_route_extended_t;
2100 struct s_rule_route {
2101 xbt_dynar_t re_str_link; // dynar of char*
2106 struct s_rule_route_extended {
2107 s_rule_route_t generic_rule_route;
2108 char *re_src_gateway;
2109 char *re_dst_gateway;
2112 static void rule_route_free(void *e)
2114 rule_route_t *elem = (rule_route_t *) (e);
2116 xbt_dynar_free(&(*elem)->re_str_link);
2117 pcre_free((*elem)->re_src);
2118 pcre_free((*elem)->re_dst);
2124 static void rule_route_extended_free(void *e)
2126 rule_route_extended_t *elem = (rule_route_extended_t *) e;
2128 xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link);
2129 pcre_free((*elem)->generic_rule_route.re_src);
2130 pcre_free((*elem)->generic_rule_route.re_dst);
2131 xbt_free((*elem)->re_src_gateway);
2132 xbt_free((*elem)->re_dst_gateway);
2137 /* Parse routing model functions */
2139 static void model_rulebased_set_processing_unit(routing_component_t rc,
2142 routing_component_rulebased_t routing =
2143 (routing_component_rulebased_t) rc;
2144 xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
2147 static void model_rulebased_set_autonomous_system(routing_component_t rc,
2150 routing_component_rulebased_t routing =
2151 (routing_component_rulebased_t) rc;
2152 xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
2156 static void model_rulebased_set_route(routing_component_t rc,
2157 const char *src, const char *dst,
2158 name_route_extended_t route)
2160 routing_component_rulebased_t routing =
2161 (routing_component_rulebased_t) rc;
2162 rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
2165 ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL);
2166 xbt_assert3(ruleroute->re_src,
2167 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2168 erroffset, src, error);
2169 ruleroute->re_dst = pcre_compile(dst, 0, &error, &erroffset, NULL);
2170 xbt_assert3(ruleroute->re_src,
2171 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2172 erroffset, dst, error);
2173 ruleroute->re_str_link = route->generic_route.link_list;
2174 xbt_dynar_push(routing->list_route, &ruleroute);
2178 static void model_rulebased_set_ASroute(routing_component_t rc,
2179 const char *src, const char *dst,
2180 name_route_extended_t route)
2182 routing_component_rulebased_t routing =
2183 (routing_component_rulebased_t) rc;
2184 rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
2187 ruleroute_e->generic_rule_route.re_src =
2188 pcre_compile(src, 0, &error, &erroffset, NULL);
2189 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2190 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2191 erroffset, src, error);
2192 ruleroute_e->generic_rule_route.re_dst =
2193 pcre_compile(dst, 0, &error, &erroffset, NULL);
2194 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2195 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2196 erroffset, dst, error);
2197 ruleroute_e->generic_rule_route.re_str_link =
2198 route->generic_route.link_list;
2199 ruleroute_e->re_src_gateway = route->src_gateway;
2200 ruleroute_e->re_dst_gateway = route->dst_gateway;
2201 xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
2202 xbt_free(route->src_gateway);
2203 xbt_free(route->dst_gateway);
2207 static void model_rulebased_set_bypassroute(routing_component_t rc,
2210 route_extended_t e_route)
2212 xbt_die("bypass routing not supported for Route-Based model");
2215 #define BUFFER_SIZE 4096 /* result buffer size */
2216 #define OVECCOUNT 30 /* should be a multiple of 3 */
2218 static char *remplace(char *value, const char **src_list, int src_size,
2219 const char **dst_list, int dst_size)
2222 char result_result[BUFFER_SIZE];
2223 int i_result_buffer;
2224 int value_length = (int) strlen(value);
2228 i_result_buffer = 0;
2230 if (value[i] == '$') {
2234 int number_length = 0;
2235 while ('0' <= value[i + number_length]
2236 && value[i + number_length] <= '9') {
2239 xbt_assert2(number_length != 0,
2240 "bad string parameter, no number indication, at offset: %d (\"%s\")",
2244 number = atoi(value + i);
2245 i = i + number_length;
2246 xbt_assert2(i + 2 < value_length,
2247 "bad string parameter, too few chars, at offset: %d (\"%s\")",
2250 // solve the indication
2251 const char **param_list;
2253 if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') {
2254 param_list = src_list;
2255 param_size = src_size;
2256 } else if (value[i] == 'd' && value[i + 1] == 's'
2257 && value[i + 2] == 't') {
2258 param_list = dst_list;
2259 param_size = dst_size;
2262 "bad string parameter, support only \"src\" and \"dst\", at offset: %d (\"%s\")",
2267 xbt_assert4(param_size >= number,
2268 "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",
2269 i, value, param_size, number);
2271 const char *param = param_list[number];
2272 int size = strlen(param);
2274 for (cp = 0; cp < size; cp++) {
2275 result_result[i_result_buffer] = param[cp];
2277 if (i_result_buffer >= BUFFER_SIZE)
2281 result_result[i_result_buffer] = value[i];
2286 } while (i < value_length && i_result_buffer < BUFFER_SIZE);
2288 xbt_assert2(i_result_buffer < BUFFER_SIZE,
2289 "solving string \"%s\", small buffer size (%d)", value,
2291 result_result[i_result_buffer] = 0;
2292 return xbt_strdup(result_result);
2295 static route_extended_t rulebased_get_route(routing_component_t rc,
2298 static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
2300 xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
2301 routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
2303 xbt_dict_cursor_t c1 = NULL;
2307 char *router = NULL;
2308 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2309 if (strstr (k1, "router")){
2314 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2317 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2318 route_extended_t route = rulebased_get_route (rc, router, k1);
2320 int number_of_links = xbt_dynar_length(route->generic_route.link_list);
2321 if (number_of_links != 3) {
2322 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2326 xbt_dynar_get_cpy (route->generic_route.link_list, 2, &link_ptr);
2327 onelink_t onelink = xbt_new0 (s_onelink_t, 1);
2328 onelink->src = xbt_strdup (k1);
2329 onelink->dst = xbt_strdup (router);
2330 onelink->link_ptr = link_ptr;
2331 xbt_dynar_push (ret, &onelink);
2336 /* Business methods */
2337 static route_extended_t rulebased_get_route(routing_component_t rc,
2341 xbt_assert1(rc && src
2343 "Invalid params for \"get_route\" function at AS \"%s\"",
2346 /* set utils vars */
2347 routing_component_rulebased_t routing =
2348 (routing_component_rulebased_t) rc;
2350 int are_processing_units;
2351 xbt_dynar_t rule_list;
2352 if (xbt_dict_get_or_null(routing->dict_processing_units, src)
2353 && xbt_dict_get_or_null(routing->dict_processing_units, dst)) {
2354 are_processing_units = 1;
2355 rule_list = routing->list_route;
2356 } else if (xbt_dict_get_or_null(routing->dict_autonomous_systems, src)
2357 && xbt_dict_get_or_null(routing->dict_autonomous_systems,
2359 are_processing_units = 0;
2360 rule_list = routing->list_ASroute;
2363 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
2368 int src_length = (int) strlen(src);
2369 int dst_length = (int) strlen(dst);
2371 xbt_dynar_t links_list =
2372 xbt_dynar_new(global_routing->size_of_link, NULL);
2374 rule_route_t ruleroute;
2376 int ovector_src[OVECCOUNT];
2377 int ovector_dst[OVECCOUNT];
2378 const char **list_src = NULL;
2379 const char **list_dst = NULL;
2380 xbt_dynar_foreach(rule_list, cpt, ruleroute) {
2382 pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0,
2383 ovector_src, OVECCOUNT);
2386 pcre_exec(ruleroute->re_dst, NULL, dst, dst_length, 0, 0,
2387 ovector_dst, OVECCOUNT);
2389 xbt_assert1(!pcre_get_substring_list
2390 (src, ovector_src, rc_src, &list_src),
2391 "error solving substring list for src \"%s\"", src);
2392 xbt_assert1(!pcre_get_substring_list
2393 (dst, ovector_dst, rc_dst, &list_dst),
2394 "error solving substring list for src \"%s\"", dst);
2396 xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) {
2397 char *new_link_name =
2398 remplace(link_name, list_src, rc_src, list_dst, rc_dst);
2400 xbt_dict_get_or_null(surf_network_model->resource_set,
2403 xbt_dynar_push(links_list, &link);
2405 THROW1(mismatch_error, 0, "Link %s not found", new_link_name);
2406 xbt_free(new_link_name);
2410 if (rc_src >= 0 && rc_dst >= 0)
2414 route_extended_t new_e_route = NULL;
2415 if (rc_src >= 0 && rc_dst >= 0) {
2416 new_e_route = xbt_new0(s_route_extended_t, 1);
2417 new_e_route->generic_route.link_list = links_list;
2418 } else if (!strcmp(src, dst) && are_processing_units) {
2419 new_e_route = xbt_new0(s_route_extended_t, 1);
2420 xbt_dynar_push(links_list, &(global_routing->loopback));
2421 new_e_route->generic_route.link_list = links_list;
2423 xbt_dynar_free(&link_list);
2426 if (!are_processing_units && new_e_route) {
2427 rule_route_extended_t ruleroute_extended =
2428 (rule_route_extended_t) ruleroute;
2429 new_e_route->src_gateway =
2430 remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
2432 new_e_route->dst_gateway =
2433 remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
2438 pcre_free_substring_list(list_src);
2440 pcre_free_substring_list(list_dst);
2445 static route_extended_t rulebased_get_bypass_route(routing_component_t rc,
2452 static void rulebased_finalize(routing_component_t rc)
2454 routing_component_rulebased_t routing =
2455 (routing_component_rulebased_t) rc;
2457 xbt_dict_free(&routing->dict_processing_units);
2458 xbt_dict_free(&routing->dict_autonomous_systems);
2459 xbt_dynar_free(&routing->list_route);
2460 xbt_dynar_free(&routing->list_ASroute);
2461 /* Delete structure */
2466 /* Creation routing model functions */
2467 static void *model_rulebased_create(void)
2469 routing_component_rulebased_t new_component =
2470 xbt_new0(s_routing_component_rulebased_t, 1);
2471 new_component->generic_routing.set_processing_unit =
2472 model_rulebased_set_processing_unit;
2473 new_component->generic_routing.set_autonomous_system =
2474 model_rulebased_set_autonomous_system;
2475 new_component->generic_routing.set_route = model_rulebased_set_route;
2476 new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
2477 new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
2478 new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
2479 new_component->generic_routing.get_route = rulebased_get_route;
2480 new_component->generic_routing.get_bypass_route = generic_get_bypassroute; //rulebased_get_bypass_route;
2481 new_component->generic_routing.finalize = rulebased_finalize;
2482 /* initialization of internal structures */
2483 new_component->dict_processing_units = xbt_dict_new();
2484 new_component->dict_autonomous_systems = xbt_dict_new();
2485 new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
2486 new_component->list_ASroute =
2487 xbt_dynar_new(sizeof(rule_route_extended_t),
2488 &rule_route_extended_free);
2489 return new_component;
2492 static void model_rulebased_load(void)
2494 /* use "surfxml_add_callback" to add a parse function call */
2497 static void model_rulebased_unload(void)
2499 /* use "surfxml_del_callback" to remove a parse function call */
2502 static void model_rulebased_end(void)
2506 #endif /* HAVE_PCRE_LIB */
2508 /* ************************************************************************** */
2509 /* ******************************* NO ROUTING ******************************* */
2511 /* Routing model structure */
2513 s_routing_component_t generic_routing;
2514 } s_routing_component_none_t, *routing_component_none_t;
2516 /* Business methods */
2517 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc)
2522 static route_extended_t none_get_route(routing_component_t rc,
2523 const char *src, const char *dst)
2528 static route_extended_t none_get_bypass_route(routing_component_t rc,
2535 static void none_finalize(routing_component_t rc)
2540 static void none_set_processing_unit(routing_component_t rc,
2545 static void none_set_autonomous_system(routing_component_t rc,
2550 /* Creation routing model functions */
2551 static void *model_none_create(void)
2553 routing_component_none_t new_component =
2554 xbt_new0(s_routing_component_none_t, 1);
2555 new_component->generic_routing.set_processing_unit =
2556 none_set_processing_unit;
2557 new_component->generic_routing.set_autonomous_system =
2558 none_set_autonomous_system;
2559 new_component->generic_routing.set_route = NULL;
2560 new_component->generic_routing.set_ASroute = NULL;
2561 new_component->generic_routing.set_bypassroute = NULL;
2562 new_component->generic_routing.get_route = none_get_route;
2563 new_component->generic_routing.get_onelink_routes =
2564 none_get_onelink_routes;
2565 new_component->generic_routing.get_bypass_route = none_get_bypass_route;
2566 new_component->generic_routing.finalize = none_finalize;
2567 return new_component;
2570 static void model_none_load(void)
2574 static void model_none_unload(void)
2578 static void model_none_end(void)
2582 /* ************************************************** */
2583 /* ********** PATERN FOR NEW ROUTING **************** */
2585 /* The minimal configuration of a new routing model need the next functions,
2586 * also you need to set at the start of the file, the new model in the model
2587 * list. Remember keep the null ending of the list.
2589 /*** Routing model structure ***/
2591 // s_routing_component_t generic_routing;
2592 // /* things that your routing model need */
2593 // } s_routing_component_NEW_t,*routing_component_NEW_t;
2595 /*** Parse routing model functions ***/
2596 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
2597 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
2598 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
2599 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
2600 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
2602 /*** Business methods ***/
2603 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2604 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2605 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
2607 /*** Creation routing model functions ***/
2608 // static void* model_NEW_create(void) {
2609 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
2610 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
2611 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
2612 // new_component->generic_routing.set_route = model_NEW_set_route;
2613 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
2614 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
2615 // new_component->generic_routing.get_route = NEW_get_route;
2616 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
2617 // new_component->generic_routing.finalize = NEW_finalize;
2618 // /* initialization of internal structures */
2619 // return new_component;
2620 // } /* mandatory */
2621 // static void model_NEW_load(void) {} /* mandatory */
2622 // static void model_NEW_unload(void) {} /* mandatory */
2623 // static void model_NEW_end(void) {} /* mandatory */
2625 /* ************************************************************************** */
2626 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
2628 static void generic_set_processing_unit(routing_component_t rc,
2631 DEBUG1("Load process unit \"%s\"", name);
2632 int *id = xbt_new0(int, 1);
2633 xbt_dict_t _to_index;
2634 _to_index = current_routing->to_index;
2635 *id = xbt_dict_length(_to_index);
2636 xbt_dict_set(_to_index, name, id, xbt_free);
2639 static void generic_set_autonomous_system(routing_component_t rc,
2642 DEBUG1("Load Autonomous system \"%s\"", name);
2643 int *id = xbt_new0(int, 1);
2644 xbt_dict_t _to_index;
2645 _to_index = current_routing->to_index;
2646 *id = xbt_dict_length(_to_index);
2647 xbt_dict_set(_to_index, name, id, xbt_free);
2650 static int surf_pointer_resource_cmp(const void *a, const void *b) {
2656 static int surf_link_resource_cmp(const void *a, const void *b) {
2657 if( memcmp(a,b,global_routing->size_of_link) == 0 );
2662 static void generic_set_route(routing_component_t rc, const char *src,
2663 const char *dst, name_route_t route)
2665 DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
2666 xbt_dict_t _parse_routes;
2667 xbt_dict_t _to_index;
2669 int *src_id, *dst_id,i;
2670 unsigned long nb_links = xbt_dynar_length(route->link_name_list);
2672 _to_index = current_routing->to_index;
2673 _parse_routes = current_routing->parse_routes;
2675 src_id = xbt_dict_get_or_null(_to_index, src);
2676 dst_id = xbt_dict_get_or_null(_to_index, dst);
2677 route_name = bprintf("%d#%d", *src_id, *dst_id);
2679 route_t route_to_test;
2680 route_t route_sym = xbt_new0(s_route_t, 1);
2683 && dst_id, "Network elements %s or %s not found", src, dst);
2685 xbt_assert2(xbt_dynar_length(route->link_name_list) > 0,
2686 "Invalid count of links, must be greater than zero (%s,%s)",
2689 route_to_test = xbt_dict_get_or_null(_parse_routes, route_name);
2692 xbt_assert2(!xbt_dynar_compare(
2693 (void*)route->link_name_list,
2694 (void*)route_to_test->link_list,
2695 (int_f_cpvoid_cpvoid_t) surf_link_resource_cmp),
2696 "The route between \"%s\" and \"%s\" already exist", src,dst);
2699 xbt_dict_set(_parse_routes, bprintf("%d#%d", *src_id, *dst_id), route, NULL);
2702 if(A_surfxml_route_symetrical == A_surfxml_route_symetrical_YES)
2704 route_sym->link_list = xbt_dynar_new(sizeof(char *),NULL);
2706 for(i=nb_links ; i>0 ; i--)
2708 char *link_name = xbt_new0(char,strlen(xbt_dynar_get_as(route->link_name_list, i-1, char *)));
2709 link_name = xbt_strdup(xbt_dynar_get_as(route->link_name_list, i-1, char *));
2710 xbt_dynar_push_as(route_sym->link_list ,char *, link_name);
2712 DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
2714 route_to_test = xbt_dict_get_or_null(_parse_routes, bprintf("%d#%d",*dst_id, *src_id));
2717 xbt_assert2(!xbt_dynar_compare(
2718 (void*)route_sym->link_list,
2719 (void*)route_to_test->link_list,
2720 (int_f_cpvoid_cpvoid_t) strcmp),
2721 "The route between \"%s\" and \"%s\" already exist", dst,src);
2724 xbt_dict_set(_parse_routes, bprintf("%d#%d",*dst_id, *src_id), route_sym, NULL);
2728 xbt_free(route_name);
2731 static void generic_set_ASroute(routing_component_t rc, const char *src,
2732 const char *dst, route_extended_t e_route)
2734 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
2735 e_route->src_gateway, dst, e_route->dst_gateway);
2737 xbt_dict_t _parse_routes;
2738 xbt_dict_t _to_index;
2740 int *src_id, *dst_id;
2741 _to_index = current_routing->to_index;
2742 _parse_routes = current_routing->parse_routes;
2744 src_id = xbt_dict_get_or_null(_to_index, src);
2745 dst_id = xbt_dict_get_or_null(_to_index, dst);
2746 route_name = bprintf("%d#%d", *src_id, *dst_id);
2747 route_t route_to_test;
2750 && dst_id, "Network elements %s or %s not found", src, dst);
2752 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2753 "Invalid count of links, must be greater than zero (%s,%s)",
2756 route_to_test = xbt_dict_get_or_null(_parse_routes, route_name);
2759 xbt_assert4(!xbt_dynar_compare(
2760 (void*) (&e_route->generic_route)->link_list,
2761 (void*) route_to_test->link_list,
2762 (int_f_cpvoid_cpvoid_t) strcmp),
2763 "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
2764 src, e_route->src_gateway, dst, e_route->dst_gateway);
2766 route_name = bprintf("%d#%d", *src_id, *dst_id);
2767 xbt_dict_set(_parse_routes, route_name, e_route, NULL);
2768 xbt_free(route_name);
2770 unsigned long nb_links = xbt_dynar_length(e_route->generic_route.link_list);
2772 if(A_surfxml_ASroute_symetrical == A_surfxml_ASroute_symetrical_YES)
2775 route_extended_t route_sym = xbt_new0(s_route_extended_t, 1);
2776 route_sym->generic_route.link_list = xbt_dynar_new(sizeof(char *),NULL);
2777 for(i=nb_links ; i>0 ; i--)
2779 char *link_name = xbt_new0(char,strlen(xbt_dynar_get_as(e_route->generic_route.link_list, i-1, char *)));
2780 link_name = bprintf("%s",xbt_dynar_get_as(e_route->generic_route.link_list, i-1, char *));
2781 xbt_dynar_push_as(route_sym->generic_route.link_list ,char *, link_name);
2783 route_sym->src_gateway = xbt_new0( char,strlen(e_route->dst_gateway) );
2784 route_sym->src_gateway = bprintf("%s",e_route->dst_gateway);
2785 route_sym->dst_gateway = xbt_new0( char,strlen(e_route->src_gateway) );
2786 route_sym->dst_gateway = bprintf("%s",e_route->src_gateway);
2787 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",dst, route_sym->src_gateway,src,route_sym->dst_gateway);
2789 route_to_test = xbt_dict_get_or_null(_parse_routes, bprintf("%d#%d", *dst_id, *src_id));
2791 xbt_assert4(!xbt_dynar_compare(
2792 (void*) (&route_sym->generic_route)->link_list,
2793 (void*) route_to_test->link_list,
2794 (int_f_cpvoid_cpvoid_t) strcmp),
2795 "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
2796 dst, route_sym->src_gateway, src, route_sym->dst_gateway);
2797 xbt_dict_set(_parse_routes, bprintf("%d#%d", *dst_id, *src_id), route_sym, NULL);
2802 static void generic_set_bypassroute(routing_component_t rc,
2803 const char *src, const char *dst,
2804 route_extended_t e_route)
2806 DEBUG2("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
2807 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2810 route_name = bprintf("%s#%s", src, dst);
2811 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2812 "Invalid count of links, must be greater than zero (%s,%s)",
2814 xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
2815 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
2816 src, e_route->src_gateway, dst, e_route->dst_gateway);
2818 route_extended_t new_e_route =
2819 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
2820 xbt_dynar_free(&(e_route->generic_route.link_list));
2823 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
2824 (void (*)(void *)) generic_free_extended_route);
2825 xbt_free(route_name);
2828 /* ************************************************************************** */
2829 /* *********************** GENERIC BUSINESS METHODS ************************* */
2831 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
2833 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
2836 static route_extended_t generic_get_bypassroute(routing_component_t rc,
2840 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2841 routing_component_t src_as, dst_as;
2842 int index_src, index_dst;
2843 xbt_dynar_t path_src = NULL;
2844 xbt_dynar_t path_dst = NULL;
2845 routing_component_t current = NULL;
2846 routing_component_t *current_src = NULL;
2847 routing_component_t *current_dst = NULL;
2849 /* (1) find the as where the src and dst are located */
2850 src_as = ((network_element_info_t)
2851 xbt_dict_get_or_null(global_routing->where_network_elements,
2852 src))->rc_component;
2853 dst_as = ((network_element_info_t)
2854 xbt_dict_get_or_null(global_routing->where_network_elements,
2855 dst))->rc_component;
2858 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
2861 /* (2) find the path to the root routing component */
2862 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
2864 while (current != NULL) {
2865 xbt_dynar_push(path_src, ¤t);
2866 current = current->routing_father;
2868 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
2870 while (current != NULL) {
2871 xbt_dynar_push(path_dst, ¤t);
2872 current = current->routing_father;
2875 /* (3) find the common father */
2876 index_src = (path_src->used) - 1;
2877 index_dst = (path_dst->used) - 1;
2878 current_src = xbt_dynar_get_ptr(path_src, index_src);
2879 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2880 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
2881 routing_component_t *tmp_src, *tmp_dst;
2882 tmp_src = xbt_dynar_pop_ptr(path_src);
2883 tmp_dst = xbt_dynar_pop_ptr(path_dst);
2886 current_src = xbt_dynar_get_ptr(path_src, index_src);
2887 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2890 int max_index_src = (path_src->used) - 1;
2891 int max_index_dst = (path_dst->used) - 1;
2893 int max_index = max(max_index_src, max_index_dst);
2896 route_extended_t e_route_bypass = NULL;
2898 for (max = 0; max <= max_index; max++) {
2899 for (i = 0; i < max; i++) {
2900 if (i <= max_index_src && max <= max_index_dst) {
2901 char *route_name = bprintf("%s#%s",
2902 (*(routing_component_t *)
2904 (path_src, i)))->name,
2905 (*(routing_component_t *)
2907 (path_dst, max)))->name);
2909 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2910 xbt_free(route_name);
2914 if (max <= max_index_src && i <= max_index_dst) {
2915 char *route_name = bprintf("%s#%s",
2916 (*(routing_component_t *)
2918 (path_src, max)))->name,
2919 (*(routing_component_t *)
2921 (path_dst, i)))->name);
2923 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2924 xbt_free(route_name);
2933 if (max <= max_index_src && max <= max_index_dst) {
2934 char *route_name = bprintf("%s#%s",
2935 (*(routing_component_t *)
2937 (path_src, max)))->name,
2938 (*(routing_component_t *)
2940 (path_dst, max)))->name);
2941 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2942 xbt_free(route_name);
2948 xbt_dynar_free(&path_src);
2949 xbt_dynar_free(&path_dst);
2951 route_extended_t new_e_route = NULL;
2953 if (e_route_bypass) {
2955 unsigned int cpt = 0;
2956 new_e_route = xbt_new0(s_route_extended_t, 1);
2957 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
2958 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
2959 new_e_route->generic_route.link_list =
2960 xbt_dynar_new(global_routing->size_of_link, NULL);
2961 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
2962 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
2969 /* ************************************************************************** */
2970 /* ************************* GENERIC AUX FUNCTIONS ************************** */
2972 static route_extended_t
2973 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
2974 void *data, int order)
2978 route_extended_t e_route, new_e_route;
2981 xbt_dynar_t links = NULL, links_id = NULL;
2983 new_e_route = xbt_new0(s_route_extended_t, 1);
2984 new_e_route->generic_route.link_list =
2985 xbt_dynar_new(global_routing->size_of_link, NULL);
2986 new_e_route->src_gateway = NULL;
2987 new_e_route->dst_gateway = NULL;
2989 xbt_assert0(hierarchy == SURF_ROUTING_BASE
2990 || hierarchy == SURF_ROUTING_RECURSIVE,
2991 "the hierarchy type is not defined");
2993 if (hierarchy == SURF_ROUTING_BASE) {
2995 route = (route_t) data;
2996 links = route->link_list;
2998 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
3000 e_route = (route_extended_t) data;
3001 xbt_assert0(e_route->src_gateway
3002 && e_route->dst_gateway, "bad gateway, is null");
3003 links = e_route->generic_route.link_list;
3005 /* remeber not erase the gateway names */
3006 new_e_route->src_gateway = e_route->src_gateway;
3007 new_e_route->dst_gateway = e_route->dst_gateway;
3010 links_id = new_e_route->generic_route.link_list;
3012 xbt_dynar_foreach(links, cpt, link_name) {
3015 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3018 xbt_dynar_push(links_id, &link);
3020 xbt_dynar_unshift(links_id, &link);
3022 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3028 static void generic_free_route(route_t route)
3031 xbt_dynar_free(&(route->link_list));
3036 static void generic_free_extended_route(route_extended_t e_route)
3039 xbt_dynar_free(&(e_route->generic_route.link_list));
3040 if (e_route->src_gateway)
3041 xbt_free(e_route->src_gateway);
3042 if (e_route->dst_gateway)
3043 xbt_free(e_route->dst_gateway);
3048 static routing_component_t generic_as_exist(routing_component_t find_from,
3049 routing_component_t to_find)
3051 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3052 xbt_dict_cursor_t cursor = NULL;
3055 routing_component_t elem;
3056 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
3057 if (to_find == elem || generic_as_exist(elem, to_find)) {
3067 static routing_component_t
3068 generic_autonomous_system_exist(routing_component_t rc, char *element)
3070 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3071 routing_component_t element_as, result, elem;
3072 xbt_dict_cursor_t cursor = NULL;
3074 element_as = ((network_element_info_t)
3075 xbt_dict_get_or_null
3076 (global_routing->where_network_elements,
3077 element))->rc_component;
3078 result = ((routing_component_t) - 1);
3079 if (element_as != rc)
3080 result = generic_as_exist(rc, element_as);
3084 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
3085 found = !strcmp(elem->name, element);
3095 static routing_component_t
3096 generic_processing_units_exist(routing_component_t rc, char *element)
3098 routing_component_t element_as;
3099 element_as = ((network_element_info_t)
3100 xbt_dict_get_or_null
3101 (global_routing->where_network_elements,
3102 element))->rc_component;
3103 if (element_as == rc)
3105 return generic_as_exist(rc, element_as);
3108 static void generic_src_dst_check(routing_component_t rc, const char *src,
3112 routing_component_t src_as = ((network_element_info_t)
3113 xbt_dict_get_or_null
3114 (global_routing->where_network_elements,
3115 src))->rc_component;
3116 routing_component_t dst_as = ((network_element_info_t)
3117 xbt_dict_get_or_null
3118 (global_routing->where_network_elements,
3119 dst))->rc_component;
3121 xbt_assert3(src_as != NULL && dst_as != NULL,
3122 "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
3123 src, dst, rc->name);
3124 xbt_assert4(src_as == dst_as,
3125 "The src(%s in %s) and dst(%s in %s) are in differents AS",
3126 src, src_as->name, dst, dst_as->name);
3127 xbt_assert2(rc == dst_as,
3128 "The routing component of src and dst is not the same as the network elements belong (%s==%s)",
3129 rc->name, dst_as->name);
3132 static void routing_parse_Sconfig(void)
3135 DEBUG0("WARNING tag config not yet implemented.");
3136 DEBUG1("Configuration name = %s",A_surfxml_config_id);
3139 static void routing_parse_Econfig(void)
3142 xbt_dict_cursor_t cursor = NULL;
3145 xbt_dict_foreach(current_property_set, cursor, key, elem) {
3146 DEBUG2("property : %s = %s",key,elem);
3150 static void routing_parse_Scluster(void)
3152 static int AX_ptr = 0;
3154 char *cluster_id = A_surfxml_cluster_id;
3155 char *cluster_prefix = A_surfxml_cluster_prefix;
3156 char *cluster_suffix = A_surfxml_cluster_suffix;
3157 char *cluster_radical = A_surfxml_cluster_radical;
3158 char *cluster_power = A_surfxml_cluster_power;
3159 char *cluster_bw = A_surfxml_cluster_bw;
3160 char *cluster_lat = A_surfxml_cluster_lat;
3161 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
3162 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
3163 char *host_id, *groups, *link_id = NULL;
3164 char *router_id, *link_router, *link_backbone, *route_src_dst;
3167 xbt_dynar_t radical_elements;
3168 xbt_dynar_t radical_ends;
3169 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
3170 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
3172 #ifndef HAVE_PCRE_LIB
3173 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3174 char *route_src, *route_dst;
3178 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3179 static unsigned int surfxml_buffer_stack_stack[1024];
3181 surfxml_buffer_stack_stack[0] = 0;
3183 surfxml_bufferstack_push(1);
3185 SURFXML_BUFFER_SET(AS_id, cluster_id);
3186 #ifdef HAVE_PCRE_LIB
3187 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3188 DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
3190 SURFXML_BUFFER_SET(AS_routing, "Full");
3191 DEBUG1("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
3193 SURFXML_START_TAG(AS);
3195 radical_elements = xbt_str_split(cluster_radical, ",");
3196 xbt_dynar_foreach(radical_elements, iter, groups) {
3197 radical_ends = xbt_str_split(groups, "-");
3198 switch (xbt_dynar_length(radical_ends)) {
3200 surf_parse_get_int(&start,
3201 xbt_dynar_get_as(radical_ends, 0, char *));
3202 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
3203 #ifndef HAVE_PCRE_LIB
3204 xbt_dynar_push_as(tab_elements_num, int, start);
3206 link_id = bprintf("%s_link_%d", cluster_id, start);
3208 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, cluster_power);
3209 A_surfxml_host_state = A_surfxml_host_state_ON;
3210 SURFXML_BUFFER_SET(host_id, host_id);
3211 SURFXML_BUFFER_SET(host_power, cluster_power);
3212 SURFXML_BUFFER_SET(host_availability, "1.0");
3213 SURFXML_BUFFER_SET(host_availability_file, "");
3214 SURFXML_BUFFER_SET(host_state_file, "");
3215 SURFXML_START_TAG(host);
3216 SURFXML_END_TAG(host);
3218 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3219 A_surfxml_link_state = A_surfxml_link_state_ON;
3220 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3221 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3222 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3223 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3224 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3225 SURFXML_BUFFER_SET(link_id, link_id);
3226 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3227 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3228 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3229 SURFXML_BUFFER_SET(link_latency_file, "");
3230 SURFXML_BUFFER_SET(link_state_file, "");
3231 SURFXML_START_TAG(link);
3232 SURFXML_END_TAG(link);
3238 surf_parse_get_int(&start,
3239 xbt_dynar_get_as(radical_ends, 0, char *));
3240 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3241 DEBUG2("Create hosts and links from %d to %d", start, end);
3242 for (i = start; i <= end; i++) {
3243 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
3244 #ifndef HAVE_PCRE_LIB
3245 xbt_dynar_push_as(tab_elements_num, int, i);
3247 link_id = bprintf("%s_link_%d", cluster_id, i);
3249 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, cluster_power);
3250 A_surfxml_host_state = A_surfxml_host_state_ON;
3251 SURFXML_BUFFER_SET(host_id, host_id);
3252 SURFXML_BUFFER_SET(host_power, cluster_power);
3253 SURFXML_BUFFER_SET(host_availability, "1.0");
3254 SURFXML_BUFFER_SET(host_availability_file, "");
3255 SURFXML_BUFFER_SET(host_state_file, "");
3256 SURFXML_START_TAG(host);
3257 SURFXML_END_TAG(host);
3259 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3260 A_surfxml_link_state = A_surfxml_link_state_ON;
3261 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3262 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3263 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3264 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3265 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3266 SURFXML_BUFFER_SET(link_id, link_id);
3267 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3268 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3269 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3270 SURFXML_BUFFER_SET(link_latency_file, "");
3271 SURFXML_BUFFER_SET(link_state_file, "");
3272 SURFXML_START_TAG(link);
3273 SURFXML_END_TAG(link);
3278 DEBUG0("Malformed radical");
3281 xbt_dynar_free(&radical_ends);
3286 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
3288 link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
3289 link_backbone = bprintf("%s_backbone", cluster_id);
3291 DEBUG1("<router id=\"%s\"/>", router_id);
3292 SURFXML_BUFFER_SET(router_id, router_id);;
3293 SURFXML_START_TAG(router);
3294 SURFXML_END_TAG(router);
3296 DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,cluster_bw, cluster_lat);
3297 A_surfxml_link_state = A_surfxml_link_state_ON;
3298 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3299 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3300 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3301 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3302 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3303 SURFXML_BUFFER_SET(link_id, link_router);
3304 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3305 SURFXML_BUFFER_SET(link_latency, cluster_lat);
3306 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3307 SURFXML_BUFFER_SET(link_latency_file, "");
3308 SURFXML_BUFFER_SET(link_state_file, "");
3309 SURFXML_START_TAG(link);
3310 SURFXML_END_TAG(link);
3312 DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bw, cluster_lat);
3313 A_surfxml_link_state = A_surfxml_link_state_ON;
3314 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3315 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
3316 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3317 SURFXML_BUFFER_SET(link_id, link_backbone);
3318 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
3319 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
3320 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3321 SURFXML_BUFFER_SET(link_latency_file, "");
3322 SURFXML_BUFFER_SET(link_state_file, "");
3323 SURFXML_START_TAG(link);
3324 SURFXML_END_TAG(link);
3326 char *new_suffix = bprintf("%s", "");
3328 radical_elements = xbt_str_split(cluster_suffix, ".");
3329 xbt_dynar_foreach(radical_elements, iter, groups) {
3330 if (strcmp(groups, "")) {
3331 new_suffix = bprintf("%s\\.%s", new_suffix, groups);
3334 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
3338 #ifdef HAVE_PCRE_LIB
3340 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
3341 DEBUG0("symetrical=\"NO\">");
3342 SURFXML_BUFFER_SET(route_src, route_src_dst);
3343 SURFXML_BUFFER_SET(route_dst, route_src_dst);
3344 A_surfxml_route_symetrical = A_surfxml_route_symetrical_NO;
3345 SURFXML_START_TAG(route);
3347 DEBUG1("<link_ctn\tid=\"%s_link_$1src\"/>", cluster_id);
3348 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1src", cluster_id));
3349 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3350 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3351 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3352 SURFXML_START_TAG(link_ctn);
3353 SURFXML_END_TAG(link_ctn);
3355 DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3356 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3357 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3358 SURFXML_START_TAG(link_ctn);
3359 SURFXML_END_TAG(link_ctn);
3361 DEBUG1("<link_ctn\tid=\"%s_link_$1dst\"/>", cluster_id);
3362 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1dst", cluster_id));
3363 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3364 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3365 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3366 SURFXML_START_TAG(link_ctn);
3367 SURFXML_END_TAG(link_ctn);
3370 SURFXML_END_TAG(route);
3372 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
3373 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
3374 if (i == xbt_dynar_length(tab_elements_num)) {
3375 route_src = router_id;
3378 bprintf("%s%d%s", cluster_prefix,
3379 xbt_dynar_get_as(tab_elements_num, i, int),
3383 if (j == xbt_dynar_length(tab_elements_num)) {
3384 route_dst = router_id;
3387 bprintf("%s%d%s", cluster_prefix,
3388 xbt_dynar_get_as(tab_elements_num, j, int),
3392 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
3393 DEBUG0("symetrical=\"NO\">");
3394 SURFXML_BUFFER_SET(route_src, route_src);
3395 SURFXML_BUFFER_SET(route_dst, route_dst);
3396 A_surfxml_route_symetrical = A_surfxml_route_symetrical_NO;
3397 SURFXML_START_TAG(route);
3399 if (i == xbt_dynar_length(tab_elements_num)) {
3400 route_src = link_router;
3403 bprintf("%s_link_%d", cluster_id,
3404 xbt_dynar_get_as(tab_elements_num, i, int));
3407 if (j == xbt_dynar_length(tab_elements_num)) {
3408 route_dst = link_router;
3411 bprintf("%s_link_%d", cluster_id,
3412 xbt_dynar_get_as(tab_elements_num, j, int));
3415 DEBUG1("<link_ctn\tid=\"%s\"/>", route_src);
3416 SURFXML_BUFFER_SET(link_ctn_id, route_src);
3417 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3418 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3419 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3420 SURFXML_START_TAG(link_ctn);
3421 SURFXML_END_TAG(link_ctn);
3423 DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3424 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3425 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3426 SURFXML_START_TAG(link_ctn);
3427 SURFXML_END_TAG(link_ctn);
3429 DEBUG1("<link_ctn\tid=\"%s\"/>", route_dst);
3430 SURFXML_BUFFER_SET(link_ctn_id, route_dst);
3431 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3432 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3433 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3434 SURFXML_START_TAG(link_ctn);
3435 SURFXML_END_TAG(link_ctn);
3438 SURFXML_END_TAG(route);
3441 xbt_dynar_free(&tab_elements_num);
3445 SURFXML_END_TAG(AS);
3448 surfxml_bufferstack_pop(1);
3452 * New methods to init the routing model component from the lua script
3456 * calling parse_S_AS_lua with lua values
3458 void routing_AS_init(const char *AS_id, const char *AS_routing)
3460 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
3464 * calling parse_E_AS_lua to fisnish the creation of routing component
3466 void routing_AS_end(const char *AS_id)
3468 parse_E_AS_lua((char *) AS_id);
3472 * add a host to the network element list
3475 void routing_add_host(const char *host_id)
3477 parse_S_host_lua((char *) host_id);
3481 * Set a new link on the actual list of link for a route or ASroute
3483 void routing_add_link(const char *link_id)
3485 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
3489 *Set the endpoints for a route
3491 void routing_set_route(const char *src_id, const char *dst_id)
3493 parse_S_route_new_and_endpoints_lua((char *) src_id, (char *) dst_id);
3497 * Store the route by calling parse_E_route_store_route
3499 void routing_store_route(void)
3501 parse_E_route_store_route();