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"
21 #include "surf/surfxml_parse.h"
23 xbt_dict_t patterns = NULL;
24 xbt_dict_t random_value = NULL;
26 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
29 routing_global_t global_routing = NULL;
30 routing_component_t current_routing = NULL;
31 model_type_t current_routing_model = NULL;
32 static double_f_cpvoid_t get_link_latency = NULL;
34 /* Prototypes of each model */
35 static void *model_full_create(void); /* create structures for full routing model */
36 static void model_full_load(void); /* load parse functions for full routing model */
37 static void model_full_unload(void); /* unload parse functions for full routing model */
38 static void model_full_end(void); /* finalize the creation of full routing model */
39 static void model_full_set_route( /* Set the route and ASroute between src and dst */
40 routing_component_t rc, const char *src, const char *dst, name_route_extended_t route);
42 static void *model_floyd_create(void); /* create structures for floyd routing model */
43 static void model_floyd_load(void); /* load parse functions for floyd routing model */
44 static void model_floyd_unload(void); /* unload parse functions for floyd routing model */
45 static void model_floyd_end(void); /* finalize the creation of floyd routing model */
46 static void model_floyd_set_route(routing_component_t rc, const char *src,
47 const char *dst, name_route_extended_t route);
49 static void *model_dijkstra_both_create(int cached); /* create by calling dijkstra or dijkstracache */
50 static void *model_dijkstra_create(void); /* create structures for dijkstra routing model */
51 static void *model_dijkstracache_create(void); /* create structures for dijkstracache routing model */
52 static void model_dijkstra_both_load(void); /* load parse functions for dijkstra routing model */
53 static void model_dijkstra_both_unload(void); /* unload parse functions for dijkstra routing model */
54 static void model_dijkstra_both_end(void); /* finalize the creation of dijkstra routing model */
55 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
56 const char *dst, name_route_extended_t route);
58 static void *model_rulebased_create(void); /* create structures for rulebased routing model */
59 static void model_rulebased_load(void); /* load parse functions for rulebased routing model */
60 static void model_rulebased_unload(void); /* unload parse functions for rulebased routing model */
61 static void model_rulebased_end(void); /* finalize the creation of rulebased routing model */
63 static void *model_none_create(void); /* none routing model */
64 static void model_none_load(void); /* none routing model */
65 static void model_none_unload(void); /* none routing model */
66 static void model_none_end(void); /* none routing model */
68 static void routing_parse_Scluster(void); /*cluster bypass */
69 static void routing_parse_Speer(void); /*peer bypass */
70 static void routing_parse_Srandom(void); /*random bypass */
71 static void routing_parse_Erandom(void); /*random bypass */
73 static void routing_parse_Sconfig(void); /*config Tag */
74 static void routing_parse_Econfig(void); /*config Tag */
76 static char* replace_random_parameter(char * chaine);
78 /* this lines are only for replace use like index in the model table */
83 SURF_MODEL_DIJKSTRACACHE,
91 /* must be finish with null and carefull if change de order */
92 struct s_model_type routing_models[] = { {"Full",
93 "Full routing data (fast, large memory requirements, fully expressive)",
99 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
100 model_floyd_create, model_floyd_load, model_floyd_unload,
103 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
104 model_dijkstra_create, model_dijkstra_both_load,
105 model_dijkstra_both_unload, model_dijkstra_both_end},
107 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
108 model_dijkstracache_create, model_dijkstra_both_load,
109 model_dijkstra_both_unload, model_dijkstra_both_end},
110 {"none", "No routing (usable with Constant network only)",
111 model_none_create, model_none_load, model_none_unload, model_none_end},
113 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
114 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
115 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
116 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
118 {NULL, NULL, NULL, NULL, NULL, NULL}
121 /* ************************************************************************** */
122 /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
124 static void generic_set_processing_unit(routing_component_t rc,
126 static void generic_set_autonomous_system(routing_component_t rc,
128 static void generic_set_bypassroute(routing_component_t rc,
129 const char *src, const char *dst,
130 route_extended_t e_route);
132 static int surf_link_resource_cmp(const void *a, const void *b);
133 static int surf_pointer_resource_cmp(const void *a, const void *b);
135 /* ************************************************************************** */
136 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
138 static double generic_get_link_latency(routing_component_t rc, const char *src, const char *dst);
139 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc);
140 static route_extended_t generic_get_bypassroute(routing_component_t rc,
144 /* ************************************************************************** */
145 /* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */
147 static route_extended_t
148 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
149 void *data, int order);
151 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
152 void *data, int order);
153 static void generic_free_route(route_t route);
154 static void generic_free_extended_route(route_extended_t e_route);
155 static routing_component_t
156 generic_autonomous_system_exist(routing_component_t rc, char *element);
157 static routing_component_t
158 generic_processing_units_exist(routing_component_t rc, char *element);
159 static void generic_src_dst_check(routing_component_t rc, const char *src,
162 /* ************************************************************************** */
163 /* **************************** GLOBAL FUNCTIONS **************************** */
165 /* global parse functions */
166 static const char *src = NULL; /* temporary store the source name of a route */
167 static const char *dst = NULL; /* temporary store the destination name of a route */
168 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
169 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
170 static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
172 static xbt_dict_t coordinates = NULL;
175 static double eculidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
177 double src_coord, dst_coord;
179 src_coord = atof(xbt_dynar_get_as(src, index, char *));
180 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
182 return (src_coord-dst_coord)*(src_coord-dst_coord);
186 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst)
188 double euclidean_dist;
189 xbt_dynar_t src_ctn, dst_ctn;
190 src_ctn = xbt_dict_get(coordinates, src);
191 dst_ctn = xbt_dict_get(coordinates, dst);
193 euclidean_dist = sqrt (eculidean_dist_comp(0,src_ctn,dst_ctn)+eculidean_dist_comp(1,src_ctn,dst_ctn))
194 +fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
196 xbt_assert2(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
198 return euclidean_dist;
201 x = atof(xbt_dynar_get_as(src_ctn, 0, char *))-atof(xbt_dynar_get_as(dst_ctn, 0, char *));
202 y = atof(xbt_dynar_get_as(src_ctn, 1, char *));
203 h = atof(xbt_dynar_get_as(ctn, 2, char *));
204 sqrt((c1->x - c2->x) * (c1->x - c2->x) + (c1->y - c2->y) * (c1->y - c2->y)) + fabs(c1->h) + fabs(c2->h);
206 if (strcmp(coord,"")) {
207 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
208 xbt_dynar_shrink(ctn,0);
209 xbt_dict_set (coordinates,host_id,ctn,NULL);
215 * \brief Add a "host" to the network element list
217 static void parse_S_host(const char *host_id, const char* coord)
219 network_element_info_t info = NULL;
220 if (current_routing->hierarchy == SURF_ROUTING_NULL)
221 current_routing->hierarchy = SURF_ROUTING_BASE;
222 xbt_assert1(!xbt_dict_get_or_null
223 (global_routing->where_network_elements, host_id),
224 "Reading a host, processing unit \"%s\" already exists",
226 xbt_assert1(current_routing->set_processing_unit,
227 "no defined method \"set_processing_unit\" in \"%s\"",
228 current_routing->name);
229 (*(current_routing->set_processing_unit)) (current_routing, host_id);
230 info = xbt_new0(s_network_element_info_t, 1);
231 info->rc_component = current_routing;
232 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
233 xbt_dict_set(global_routing->where_network_elements, host_id,
234 (void *) info, xbt_free);
235 if (strcmp(coord,"")) {
236 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
237 xbt_dynar_shrink(ctn, 0);
238 xbt_dict_set(coordinates, host_id, ctn, xbt_dynar_free_voidp);
242 static void parse_E_host(void)
244 xbt_dict_cursor_t cursor = NULL;
248 xbt_dict_foreach(current_property_set, cursor, key, elem) {
249 XBT_DEBUG("property : %s = %s",key,elem);
254 * \brief Add a host to the network element list from XML
256 static void parse_S_host_XML(void)
258 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
260 static void parse_E_host_XML(void)
266 * \brief Add a host to the network element list from lua script
268 static void parse_S_host_lua(const char *host_id, const char *coord)
270 parse_S_host(host_id, coord);
275 * \brief Add a "router" to the network element list
277 static void parse_S_router(void)
279 network_element_info_t info = NULL;
281 if (current_routing->hierarchy == SURF_ROUTING_NULL)
282 current_routing->hierarchy = SURF_ROUTING_BASE;
283 xbt_assert1(!xbt_dict_get_or_null
284 (global_routing->where_network_elements,
285 A_surfxml_router_id),
286 "Reading a router, processing unit \"%s\" already exists",
287 A_surfxml_router_id);
288 xbt_assert1(current_routing->set_processing_unit,
289 "no defined method \"set_processing_unit\" in \"%s\"",
290 current_routing->name);
291 (*(current_routing->set_processing_unit)) (current_routing,
292 A_surfxml_router_id);
293 info = xbt_new0(s_network_element_info_t, 1);
294 info->rc_component = current_routing;
295 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
296 xbt_dict_set(global_routing->where_network_elements, A_surfxml_router_id,
297 (void *) info, xbt_free);
298 if (strcmp(A_surfxml_router_coordinates,"")) {
299 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
300 xbt_dynar_shrink(ctn, 0);
301 xbt_dict_set(coordinates, A_surfxml_router_id, ctn, xbt_dynar_free_voidp);
306 * \brief Set the endponints for a route
308 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
310 if (src != NULL && dst != NULL && link_list != NULL)
311 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
315 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0,
316 "Some limits are null in the route between \"%s\" and \"%s\"",
318 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
322 * \brief Set the endpoints for a route from XML
324 static void parse_S_route_new_and_endpoints_XML(void)
326 parse_S_route_new_and_endpoints(A_surfxml_route_src,
327 A_surfxml_route_dst);
331 * \brief Set the endpoints for a route from lua
333 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
335 parse_S_route_new_and_endpoints(id_src, id_dst);
339 * \brief Set the endponints and gateways for a ASroute
341 static void parse_S_ASroute_new_and_endpoints(void)
343 if (src != NULL && dst != NULL && link_list != NULL)
344 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
345 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
346 src = A_surfxml_ASroute_src;
347 dst = A_surfxml_ASroute_dst;
348 gw_src = A_surfxml_ASroute_gw_src;
349 gw_dst = A_surfxml_ASroute_gw_dst;
350 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
351 || strlen(gw_dst) > 0,
352 "Some limits are null in the route between \"%s\" and \"%s\"",
354 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
358 * \brief Set the endponints for a bypassRoute
360 static void parse_S_bypassRoute_new_and_endpoints(void)
362 if (src != NULL && dst != NULL && link_list != NULL)
364 "Bypass Route between %s to %s can not be defined",
365 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
366 src = A_surfxml_bypassRoute_src;
367 dst = A_surfxml_bypassRoute_dst;
368 gw_src = A_surfxml_bypassRoute_gw_src;
369 gw_dst = A_surfxml_bypassRoute_gw_dst;
370 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
371 || strlen(gw_dst) > 0,
372 "Some limits are null in the route between \"%s\" and \"%s\"",
374 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
378 * \brief Set a new link on the actual list of link for a route or ASroute
380 static void parse_E_link_ctn_new_elem(const char *link_id)
383 val = xbt_strdup(link_id);
384 xbt_dynar_push(link_list, &val);
388 * \brief Set a new link on the actual list of link for a route or ASroute from XML
391 static void parse_E_link_ctn_new_elem_XML(void)
393 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
394 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
395 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
396 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
397 parse_E_link_ctn_new_elem(link_id);
400 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
401 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
402 parse_E_link_ctn_new_elem(link_id);
408 * \brief Set a new link on the actual list of link for a route or ASroute from lua
410 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
412 parse_E_link_ctn_new_elem(link_id);
416 * \brief Store the route by calling the set_route function of the current routing component
418 static void parse_E_route_store_route(void)
420 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
421 route->generic_route.link_list = link_list;
422 xbt_assert1(current_routing->set_route,
423 "no defined method \"set_route\" in \"%s\"",
424 current_routing->name);
425 (*(current_routing->set_route)) (current_routing, src, dst, route);
432 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
434 static void parse_E_ASroute_store_route(void)
436 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
437 e_route->generic_route.link_list = link_list;
438 e_route->src_gateway = xbt_strdup(gw_src);
439 e_route->dst_gateway = xbt_strdup(gw_dst);
440 xbt_assert1(current_routing->set_ASroute,
441 "no defined method \"set_ASroute\" in \"%s\"",
442 current_routing->name);
443 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
452 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
454 static void parse_E_bypassRoute_store_route(void)
456 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
457 e_route->generic_route.link_list = link_list;
458 e_route->src_gateway = xbt_strdup(gw_src);
459 e_route->dst_gateway = xbt_strdup(gw_dst);
460 xbt_assert1(current_routing->set_bypassroute,
461 "no defined method \"set_bypassroute\" in \"%s\"",
462 current_routing->name);
463 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
473 * \brief Make a new routing component
475 * make the new structure and
476 * set the parsing functions to allows parsing the part of the routing tree
478 static void parse_S_AS(char *AS_id, char *AS_routing)
480 routing_component_t new_routing;
481 model_type_t model = NULL;
482 char *wanted = AS_routing;
484 /* seach the routing model */
485 for (cpt = 0; routing_models[cpt].name; cpt++)
486 if (!strcmp(wanted, routing_models[cpt].name))
487 model = &routing_models[cpt];
488 /* if its not exist, error */
490 fprintf(stderr, "Routing model %s not found. Existing models:\n",
492 for (cpt = 0; routing_models[cpt].name; cpt++)
493 if (!strcmp(wanted, routing_models[cpt].name))
494 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
495 routing_models[cpt].desc);
499 /* make a new routing component */
500 new_routing = (routing_component_t) (*(model->create)) ();
501 new_routing->routing = model;
502 new_routing->hierarchy = SURF_ROUTING_NULL;
503 new_routing->name = xbt_strdup(AS_id);
504 new_routing->routing_sons = xbt_dict_new();
506 /* Hack for Vivaldi */
507 if(!strcmp(model->name,"Vivaldi"))
508 new_routing->get_latency = vivaldi_get_link_latency;
510 if (current_routing == NULL && global_routing->root == NULL) {
512 /* it is the first one */
513 new_routing->routing_father = NULL;
514 global_routing->root = new_routing;
516 } else if (current_routing != NULL && global_routing->root != NULL) {
518 xbt_assert1(!xbt_dict_get_or_null
519 (current_routing->routing_sons, AS_id),
520 "The AS \"%s\" already exists", AS_id);
521 /* it is a part of the tree */
522 new_routing->routing_father = current_routing;
523 /* set the father behavior */
524 if (current_routing->hierarchy == SURF_ROUTING_NULL)
525 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
526 /* add to the sons dictionary */
527 xbt_dict_set(current_routing->routing_sons, AS_id,
528 (void *) new_routing, NULL);
529 /* add to the father element list */
530 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
531 /* unload the prev parse rules */
532 (*(current_routing->routing->unload)) ();
535 THROW0(arg_error, 0, "All defined components must be belong to a AS");
537 /* set the new parse rules */
538 (*(new_routing->routing->load)) ();
539 /* set the new current component of the tree */
540 current_routing = new_routing;
544 * Detect the routing model type of the routing component from XML platforms
546 static void parse_S_AS_XML(void)
548 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
550 if (strcmp(A_surfxml_AS_coordinates,"")) {
551 XBT_DEBUG("%s coordinates : %s", A_surfxml_AS_id, A_surfxml_AS_coordinates);
552 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_AS_coordinates, " ");
553 xbt_dynar_shrink(ctn, 0);
554 xbt_dict_set(coordinates, A_surfxml_AS_id, ctn, xbt_dynar_free_voidp);
559 * define the routing model type of routing component from lua script
561 static void parse_S_AS_lua(char *id, char *mode)
563 parse_S_AS(id, mode);
568 * \brief Finish the creation of a new routing component
570 * When you finish to read the routing component, other structures must be created.
571 * the "end" method allow to do that for any routing model type
573 static void parse_E_AS(const char *AS_id)
576 if (current_routing == NULL) {
577 THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id);
579 network_element_info_t info = NULL;
580 xbt_assert1(!xbt_dict_get_or_null
581 (global_routing->where_network_elements,
582 current_routing->name), "The AS \"%s\" already exists",
583 current_routing->name);
584 info = xbt_new0(s_network_element_info_t, 1);
585 info->rc_component = current_routing->routing_father;
586 info->rc_type = SURF_NETWORK_ELEMENT_AS;
587 xbt_dict_set(global_routing->where_network_elements,
588 current_routing->name, info, xbt_free);
589 (*(current_routing->routing->unload)) ();
590 (*(current_routing->routing->end)) ();
591 current_routing = current_routing->routing_father;
592 if (current_routing != NULL)
593 (*(current_routing->routing->load)) ();
598 * \brief Finish the creation of a new routing component from XML
600 static void parse_E_AS_XML(void)
602 parse_E_AS(A_surfxml_AS_id);
606 * \brief Finish the creation of a new routing component from lua
608 static void parse_E_AS_lua(const char *id)
613 /* Aux Business methods */
616 * \brief Get the AS name of the element
618 * \param name the host name
621 static char* elements_As_name(const char *name)
623 routing_component_t as_comp;
625 /* (1) find the as where the host is located */
626 as_comp = ((network_element_info_t)
627 xbt_dict_get_or_null(global_routing->where_network_elements,
628 name))->rc_component;
629 return as_comp->name;
634 * \brief Get the AS father and the first elements of the chain
636 * \param src the source host name
637 * \param dst the destination host name
639 * Get the common father of the to processing units, and the first different
640 * father in the chain
642 static xbt_dynar_t elements_father(const char *src, const char *dst)
645 xbt_assert0(src && dst, "bad parameters for \"elements_father\" method");
647 xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
649 routing_component_t src_as, dst_as;
650 int index_src, index_dst, index_father_src, index_father_dst;
651 xbt_dynar_t path_src = NULL;
652 xbt_dynar_t path_dst = NULL;
653 routing_component_t current = NULL;
654 routing_component_t *current_src = NULL;
655 routing_component_t *current_dst = NULL;
656 routing_component_t *father = NULL;
658 /* (1) find the as where the src and dst are located */
659 src_as = ((network_element_info_t)
660 xbt_dict_get_or_null(global_routing->where_network_elements,
662 dst_as = ((network_element_info_t)
663 xbt_dict_get_or_null(global_routing->where_network_elements,
667 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
670 /* (2) find the path to the root routing component */
671 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
673 while (current != NULL) {
674 xbt_dynar_push(path_src, ¤t);
675 current = current->routing_father;
677 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
679 while (current != NULL) {
680 xbt_dynar_push(path_dst, ¤t);
681 current = current->routing_father;
684 /* (3) find the common father */
685 index_src = path_src->used - 1;
686 index_dst = path_dst->used - 1;
687 current_src = xbt_dynar_get_ptr(path_src, index_src);
688 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
689 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
690 current_src = xbt_dynar_get_ptr(path_src, index_src);
691 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
697 current_src = xbt_dynar_get_ptr(path_src, index_src);
698 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
700 /* (4) they are not in the same routing component, make the path */
701 index_father_src = index_src + 1;
702 index_father_dst = index_dst + 1;
704 if (*current_src == *current_dst)
705 father = current_src;
707 father = xbt_dynar_get_ptr(path_src, index_father_src);
709 /* (5) result generation */
710 xbt_dynar_push(result, father); /* first same the father of src and dst */
711 xbt_dynar_push(result, current_src); /* second the first different father of src */
712 xbt_dynar_push(result, current_dst); /* three the first different father of dst */
714 xbt_dynar_free(&path_src);
715 xbt_dynar_free(&path_dst);
720 /* Global Business methods */
723 * \brief Recursive function for get_route
725 * \param src the source host name
726 * \param dst the destination host name
728 * This fuction is call by "get_route". It allow to walk through the
729 * routing components tree.
731 static route_extended_t _get_route(const char *src, const char *dst)
735 unsigned int cpt = 0;
737 XBT_DEBUG("Solve route \"%s\" to \"%s\"", src, dst);
739 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
741 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
744 xbt_dynar_t elem_father_list = elements_father(src, dst);
746 routing_component_t common_father =
747 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
748 routing_component_t src_father =
749 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
750 routing_component_t dst_father =
751 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
753 e_route = xbt_new0(s_route_extended_t, 1);
754 e_route->src_gateway = NULL;
755 e_route->dst_gateway = NULL;
756 e_route->generic_route.link_list =
757 xbt_dynar_new(global_routing->size_of_link, NULL);
759 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
761 if (strcmp(src, dst)) {
763 (*(common_father->get_route)) (common_father, src, dst);
764 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
766 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
767 xbt_dynar_push(e_route->generic_route.link_list, &link);
769 generic_free_extended_route(e_route_cnt);
772 } else { /* SURF_ROUTING_RECURSIVE */
774 route_extended_t e_route_bypass = NULL;
776 if (common_father->get_bypass_route)
778 (*(common_father->get_bypass_route)) (common_father, src, dst);
781 e_route_cnt = e_route_bypass;
784 (*(common_father->get_route)) (common_father, src_father->name,
787 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
788 src_father->name, dst_father->name);
790 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
791 (e_route_cnt->dst_gateway == NULL),
792 "bad gateway for route between \"%s\" and \"%s\"", src,
795 if (strcmp(src, e_route_cnt->src_gateway)) {
796 e_route_src = _get_route(src, e_route_cnt->src_gateway);
797 xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
798 e_route_cnt->src_gateway);
799 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
800 xbt_dynar_push(e_route->generic_route.link_list, &link);
804 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
805 xbt_dynar_push(e_route->generic_route.link_list, &link);
808 if (strcmp(e_route_cnt->dst_gateway, dst)) {
809 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
810 xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
811 e_route_cnt->dst_gateway, dst);
812 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
813 xbt_dynar_push(e_route->generic_route.link_list, &link);
817 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
818 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
820 generic_free_extended_route(e_route_src);
821 generic_free_extended_route(e_route_cnt);
822 generic_free_extended_route(e_route_dst);
825 xbt_dynar_free(&elem_father_list);
830 static double _get_latency(const char *src, const char *dst)
832 double latency, latency_src, latency_dst = 0.0;
834 XBT_DEBUG("Solve route \"%s\" to \"%s\"", src, dst);
835 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
837 route_extended_t e_route_cnt;
839 xbt_dynar_t elem_father_list = elements_father(src, dst);
841 routing_component_t common_father =
842 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
843 routing_component_t src_father =
844 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
845 routing_component_t dst_father =
846 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
848 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
850 if (strcmp(src, dst)) {
852 (*(common_father->get_latency)) (common_father, src, dst);
853 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"", src,
856 } else { /* SURF_ROUTING_RECURSIVE */
857 route_extended_t e_route_bypass = NULL;
858 if (common_father->get_bypass_route)
860 (*(common_father->get_bypass_route)) (common_father, src, dst);
862 xbt_assert0(!e_route_bypass,"Bypass cannot work yet with get_latency");
865 (*(common_father->get_route)) (common_father, src_father->name,
868 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
869 src_father->name, dst_father->name);
871 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
872 (e_route_cnt->dst_gateway == NULL),
873 "bad gateway for route between \"%s\" and \"%s\"", src,
876 (*(common_father->get_latency)) (common_father, elements_As_name(src),
877 elements_As_name(dst));
879 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"",
880 src_father->name, dst_father->name);
883 if (src != e_route_cnt->src_gateway) {
885 latency_src = _get_latency(src, e_route_cnt->src_gateway);
886 xbt_assert2(latency_src>=0, "no route between \"%s\" and \"%s\"", src,
887 e_route_cnt->src_gateway);
888 latency += latency_src;
891 if (e_route_cnt->dst_gateway != dst) {
893 latency_dst = _get_latency(e_route_cnt->dst_gateway, dst);
894 xbt_assert2(latency_dst>=0, "no route between \"%s\" and \"%s\"",
895 e_route_cnt->dst_gateway, dst);
896 latency += latency_dst;
901 xbt_dynar_free(&elem_father_list);
907 * \brief Generic method: find a route between hosts
909 * \param src the source host name
910 * \param dst the destination host name
912 * walk through the routing components tree and find a route between hosts
913 * by calling the differents "get_route" functions in each routing component.
914 * No need to free the returned dynar. It will be freed at the next call.
916 static xbt_dynar_t get_route(const char *src, const char *dst)
919 route_extended_t e_route;
920 xbt_dynar_t elem_father_list = NULL;
921 routing_component_t common_father = NULL;
923 if (strcmp(src, dst))
924 e_route = _get_route(src, dst);
926 elem_father_list = elements_father(src, dst);
928 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
930 e_route = (*(common_father->get_route)) (common_father, src, dst);
931 xbt_dynar_free(&elem_father_list);
934 xbt_assert2(e_route, "no route between \"%s\" and \"%s\"", src, dst);
936 if (global_routing->last_route)
937 xbt_dynar_free(&(global_routing->last_route));
938 global_routing->last_route = e_route->generic_route.link_list;
940 if (e_route->src_gateway)
941 xbt_free(e_route->src_gateway);
942 if (e_route->dst_gateway)
943 xbt_free(e_route->dst_gateway);
948 if (xbt_dynar_length(global_routing->last_route) == 0)
952 return global_routing->last_route;
956 * \brief Generic method: find a route between hosts
958 * \param src the source host name
959 * \param dst the destination host name
961 * walk through the routing components tree and find a route between hosts
962 * by calling the differents "get_route" functions in each routing component.
963 * Leaves the caller the responsability to clean the returned dynar.
965 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
967 xbt_dynar_t d = get_route(src,dst);
968 global_routing->last_route = NULL;
973 static double get_latency(const char *src, const char *dst)
976 double latency = -1.0;
977 xbt_dynar_t elem_father_list = elements_father(src, dst);
978 routing_component_t common_father =
979 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
981 if (strcmp(src, dst))
982 latency = _get_latency(src, dst);
984 latency = (*(common_father->get_latency)) (common_father, src, dst);
986 xbt_assert2(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst);
987 xbt_dynar_free(&elem_father_list);
993 * \brief Recursive function for finalize
995 * \param rc the source host name
997 * This fuction is call by "finalize". It allow to finalize the
998 * AS or routing components. It delete all the structures.
1000 static void _finalize(routing_component_t rc)
1003 xbt_dict_cursor_t cursor = NULL;
1005 routing_component_t elem;
1006 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
1009 xbt_dict_t tmp_sons = rc->routing_sons;
1010 char *tmp_name = rc->name;
1011 xbt_dict_free(&tmp_sons);
1013 xbt_assert1(rc->finalize, "no defined method \"finalize\" in \"%s\"",
1014 current_routing->name);
1015 (*(rc->finalize)) (rc);
1020 * \brief Generic method: delete all the routing structures
1022 * walk through the routing components tree and delete the structures
1023 * by calling the differents "finalize" functions in each routing component
1025 static void finalize(void)
1027 /* delete recursibly all the tree */
1028 _finalize(global_routing->root);
1029 /* delete "where" dict */
1030 xbt_dict_free(&(global_routing->where_network_elements));
1031 xbt_dict_free(&(coordinates));
1032 /* delete last_route */
1033 xbt_dynar_free(&(global_routing->last_route));
1034 /* delete global routing structure */
1035 xbt_free(global_routing);
1038 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
1040 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1042 //adding my one link routes
1045 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
1047 xbt_dynar_foreach(onelink_mine, cpt, link) {
1048 xbt_dynar_push(ret, &link);
1053 xbt_dict_cursor_t cursor = NULL;
1054 routing_component_t rc_child;
1055 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
1056 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
1057 if (onelink_child) {
1058 xbt_dynar_foreach(onelink_child, cpt, link) {
1059 xbt_dynar_push(ret, &link);
1066 static xbt_dynar_t get_onelink_routes(void)
1068 return recursive_get_onelink_routes(global_routing->root);
1071 static e_surf_network_element_type_t get_network_element_type(const char
1074 network_element_info_t rc = NULL;
1075 rc = xbt_dict_get(global_routing->where_network_elements, name);
1080 * \brief Generic method: create the global routing schema
1082 * Make a global routing structure and set all the parsing functions.
1084 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
1086 /* config the uniq global routing */
1087 global_routing = xbt_new0(s_routing_global_t, 1);
1088 global_routing->where_network_elements = xbt_dict_new();
1089 global_routing->root = NULL;
1090 global_routing->get_route = get_route;
1091 global_routing->get_latency = get_latency;
1092 global_routing->get_route_no_cleanup = get_route_no_cleanup;
1093 global_routing->get_onelink_routes = get_onelink_routes;
1094 global_routing->get_network_element_type = get_network_element_type;
1095 global_routing->finalize = finalize;
1096 global_routing->loopback = loopback;
1097 global_routing->size_of_link = size_of_links;
1098 global_routing->last_route = NULL;
1099 get_link_latency = get_link_latency_fun;
1100 /* no current routing at moment */
1101 current_routing = NULL;
1103 coordinates = xbt_dict_new();
1105 /* parse generic elements */
1106 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
1107 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
1108 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
1110 surfxml_add_callback(STag_surfxml_route_cb_list,
1111 &parse_S_route_new_and_endpoints_XML);
1112 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
1113 &parse_S_ASroute_new_and_endpoints);
1114 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
1115 &parse_S_bypassRoute_new_and_endpoints);
1117 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
1118 &parse_E_link_ctn_new_elem_XML);
1120 surfxml_add_callback(ETag_surfxml_route_cb_list,
1121 &parse_E_route_store_route);
1122 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
1123 &parse_E_ASroute_store_route);
1124 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
1125 &parse_E_bypassRoute_store_route);
1127 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
1128 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
1130 surfxml_add_callback(STag_surfxml_cluster_cb_list,
1131 &routing_parse_Scluster);
1133 surfxml_add_callback(STag_surfxml_peer_cb_list,
1134 &routing_parse_Speer);
1138 instr_routing_define_callbacks();
1142 void surf_parse_add_callback_config(void)
1144 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1145 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1146 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
1147 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
1148 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1151 void surf_parse_models_setup()
1153 routing_parse_Erandom();
1154 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1155 surf_config_models_setup(platform_filename);
1156 free(platform_filename);
1159 /* ************************************************************************** */
1160 /* *************************** FULL ROUTING ********************************* */
1162 #define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
1164 /* Routing model structure */
1167 s_routing_component_t generic_routing;
1168 route_extended_t *routing_table;
1169 } s_routing_component_full_t, *routing_component_full_t;
1171 /* Business methods */
1172 static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
1174 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1176 routing_component_full_t routing = (routing_component_full_t) rc;
1177 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1178 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1179 char *k1, *d1, *k2, *d2;
1180 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1181 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1182 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k1);
1183 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k2);
1186 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1188 route_extended_t route = TO_ROUTE_FULL(*src_id, *dst_id);
1190 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1192 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1194 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1195 onelink->link_ptr = link;
1196 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1197 onelink->src = xbt_strdup(k1);
1198 onelink->dst = xbt_strdup(k2);
1199 } else if (routing->generic_routing.hierarchy ==
1200 SURF_ROUTING_RECURSIVE) {
1201 onelink->src = xbt_strdup(route->src_gateway);
1202 onelink->dst = xbt_strdup(route->dst_gateway);
1204 xbt_dynar_push(ret, &onelink);
1212 static route_extended_t full_get_route(routing_component_t rc,
1213 const char *src, const char *dst)
1215 xbt_assert1(rc && src
1217 "Invalid params for \"get_route\" function at AS \"%s\"",
1220 /* set utils vars */
1221 routing_component_full_t routing = (routing_component_full_t) rc;
1222 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1224 generic_src_dst_check(rc, src, dst);
1225 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1226 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1229 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1232 route_extended_t e_route = NULL;
1233 route_extended_t new_e_route = NULL;
1235 unsigned int cpt = 0;
1237 e_route = TO_ROUTE_FULL(*src_id, *dst_id);
1240 new_e_route = xbt_new0(s_route_extended_t, 1);
1241 new_e_route->src_gateway = xbt_strdup(e_route->src_gateway);
1242 new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway);
1243 new_e_route->generic_route.link_list =
1244 xbt_dynar_new(global_routing->size_of_link, NULL);
1245 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
1246 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1252 static void full_finalize(routing_component_t rc)
1254 routing_component_full_t routing = (routing_component_full_t) rc;
1255 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1258 /* Delete routing table */
1259 for (i = 0; i < table_size; i++)
1260 for (j = 0; j < table_size; j++)
1261 generic_free_extended_route(TO_ROUTE_FULL(i, j));
1262 xbt_free(routing->routing_table);
1263 /* Delete bypass dict */
1264 xbt_dict_free(&rc->bypassRoutes);
1265 /* Delete index dict */
1266 xbt_dict_free(&rc->to_index);
1267 /* Delete structure */
1272 /* Creation routing model functions */
1274 static void *model_full_create(void)
1276 routing_component_full_t new_component =
1277 xbt_new0(s_routing_component_full_t, 1);
1278 new_component->generic_routing.set_processing_unit =
1279 generic_set_processing_unit;
1280 new_component->generic_routing.set_autonomous_system =
1281 generic_set_autonomous_system;
1282 new_component->generic_routing.set_route = model_full_set_route;
1283 new_component->generic_routing.set_ASroute = model_full_set_route;
1284 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1285 new_component->generic_routing.get_route = full_get_route;
1286 new_component->generic_routing.get_latency = generic_get_link_latency;
1287 new_component->generic_routing.get_onelink_routes =
1288 full_get_onelink_routes;
1289 new_component->generic_routing.get_bypass_route =
1290 generic_get_bypassroute;
1291 new_component->generic_routing.finalize = full_finalize;
1292 new_component->generic_routing.to_index = xbt_dict_new();
1293 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1294 new_component->generic_routing.get_network_element_type = get_network_element_type;
1295 return new_component;
1298 static void model_full_load(void)
1300 /* use "surfxml_add_callback" to add a parse function call */
1303 static void model_full_unload(void)
1305 /* use "surfxml_del_callback" to remove a parse function call */
1308 static void model_full_end(void)
1311 route_extended_t e_route;
1313 /* set utils vars */
1314 routing_component_full_t routing =
1315 ((routing_component_full_t) current_routing);
1316 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1318 /* Create table if necessary */
1319 if(!routing->routing_table)
1320 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1322 /* Add the loopback if needed */
1323 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1324 for (i = 0; i < table_size; i++) {
1325 e_route = TO_ROUTE_FULL(i, i);
1327 e_route = xbt_new0(s_route_extended_t, 1);
1328 e_route->src_gateway = NULL;
1329 e_route->dst_gateway = NULL;
1330 e_route->generic_route.link_list =
1331 xbt_dynar_new(global_routing->size_of_link, NULL);
1332 xbt_dynar_push(e_route->generic_route.link_list,
1333 &global_routing->loopback);
1334 TO_ROUTE_FULL(i, i) = e_route;
1340 static void model_full_set_route(routing_component_t rc, const char *src,
1341 const char *dst, name_route_extended_t route)
1343 int *src_id, *dst_id;
1344 src_id = xbt_dict_get_or_null(rc->to_index, src);
1345 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1346 routing_component_full_t routing = ((routing_component_full_t) rc);
1347 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1350 && dst_id, "Network elements %s or %s not found", src, dst);
1352 xbt_assert2(xbt_dynar_length(route->generic_route.link_list) > 0,
1353 "Invalid count of links, must be greater than zero (%s,%s)",
1356 if(!routing->routing_table)
1357 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1359 if(TO_ROUTE_FULL(*src_id, *dst_id))
1363 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1364 xbt_dynar_foreach(route->generic_route.link_list,i,link_name)
1366 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1367 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1368 xbt_dynar_push(link_route_to_test,&link);
1370 xbt_assert2(!xbt_dynar_compare(
1371 (void*)TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list,
1372 (void*)link_route_to_test,
1373 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1374 "The route between \"%s\" and \"%s\" already exists. If you are trying to define a reverse route, you must set the symmetrical=no attribute to your routes tags.", src,dst);
1375 xbt_dynar_free(&link_route_to_test);
1379 if(!route->dst_gateway && !route->src_gateway)
1380 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
1382 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1383 route->src_gateway, dst, route->dst_gateway);
1384 TO_ROUTE_FULL(*src_id, *dst_id) = generic_new_extended_route(rc->hierarchy,route,1);
1385 xbt_dynar_shrink(TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list, 0);
1388 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1389 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1391 if(route->dst_gateway && route->src_gateway)
1393 char *gw_src = xbt_strdup(route->src_gateway);
1394 char *gw_dst = xbt_strdup(route->dst_gateway);
1395 route->src_gateway = gw_dst;
1396 route->dst_gateway = gw_src;
1398 if(TO_ROUTE_FULL(*dst_id, *src_id))
1402 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1403 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1405 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1406 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1407 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1408 xbt_dynar_push(link_route_to_test,&link);
1410 xbt_assert2(!xbt_dynar_compare(
1411 (void*)TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list,
1412 (void*)link_route_to_test,
1413 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1414 "The route between \"%s\" and \"%s\" already exists", src,dst);
1415 xbt_dynar_free(&link_route_to_test);
1419 if(!route->dst_gateway && !route->src_gateway)
1420 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
1422 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1423 route->src_gateway, src, route->dst_gateway);
1424 TO_ROUTE_FULL(*dst_id, *src_id) = generic_new_extended_route(rc->hierarchy,route,0);
1425 xbt_dynar_shrink(TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list, 0);
1431 /* ************************************************************************** */
1432 /* *************************** FLOYD ROUTING ******************************** */
1434 #define TO_FLOYD_COST(i,j) (routing->cost_table)[(i)+(j)*table_size]
1435 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
1436 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
1438 /* Routing model structure */
1441 s_routing_component_t generic_routing;
1442 /* vars for calculate the floyd algorith. */
1443 int *predecessor_table;
1445 route_extended_t *link_table; /* char* -> int* */
1446 } s_routing_component_floyd_t, *routing_component_floyd_t;
1448 static route_extended_t floyd_get_route(routing_component_t rc,
1449 const char *src, const char *dst);
1451 /* Business methods */
1452 static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
1454 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1456 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1457 //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1458 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1459 char *k1, *d1, *k2, *d2;
1460 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1461 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1462 route_extended_t route = floyd_get_route(rc, k1, k2);
1464 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1466 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1468 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1469 onelink->link_ptr = link;
1470 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1471 onelink->src = xbt_strdup(k1);
1472 onelink->dst = xbt_strdup(k2);
1473 } else if (routing->generic_routing.hierarchy ==
1474 SURF_ROUTING_RECURSIVE) {
1475 onelink->src = xbt_strdup(route->src_gateway);
1476 onelink->dst = xbt_strdup(route->dst_gateway);
1478 xbt_dynar_push(ret, &onelink);
1486 static route_extended_t floyd_get_route(routing_component_t rc,
1487 const char *src, const char *dst)
1489 xbt_assert1(rc && src
1491 "Invalid params for \"get_route\" function at AS \"%s\"",
1494 /* set utils vars */
1495 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1496 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1498 generic_src_dst_check(rc, src, dst);
1499 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1500 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1503 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1506 /* create a result route */
1507 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1508 new_e_route->generic_route.link_list =
1509 xbt_dynar_new(global_routing->size_of_link, NULL);
1510 new_e_route->src_gateway = NULL;
1511 new_e_route->dst_gateway = NULL;
1516 char *gw_src = NULL, *gw_dst =
1517 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1524 pred = TO_FLOYD_PRED(*src_id, pred);
1525 if (pred == -1) /* if no pred in route -> no route to host */
1527 xbt_assert2(TO_FLOYD_LINK(pred, prev_pred),
1528 "Invalid link for the route between \"%s\" or \"%s\"", src,
1531 prev_gw_src = gw_src;
1532 prev_gw_dst = gw_dst;
1534 route_extended_t e_route = TO_FLOYD_LINK(pred, prev_pred);
1535 gw_src = e_route->src_gateway;
1536 gw_dst = e_route->dst_gateway;
1541 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && !first
1542 && strcmp(gw_dst, prev_gw_src)) {
1543 xbt_dynar_t e_route_as_to_as =
1544 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1545 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1546 gw_dst, prev_gw_src);
1547 links = e_route_as_to_as;
1549 xbt_dynar_foreach(links, cpt, link) {
1550 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1556 links = e_route->generic_route.link_list;
1557 xbt_dynar_foreach(links, cpt, link) {
1558 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1562 } while (pred != *src_id);
1563 xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")",
1564 *src_id, *dst_id, src, dst);
1566 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1567 new_e_route->src_gateway = xbt_strdup(gw_src);
1568 new_e_route->dst_gateway = xbt_strdup(first_gw);
1574 static void floyd_finalize(routing_component_t rc)
1576 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1580 table_size = xbt_dict_length(routing->generic_routing.to_index);
1581 /* Delete link_table */
1582 for (i = 0; i < table_size; i++)
1583 for (j = 0; j < table_size; j++)
1584 generic_free_extended_route(TO_FLOYD_LINK(i, j));
1585 xbt_free(routing->link_table);
1586 /* Delete bypass dict */
1587 xbt_dict_free(&routing->generic_routing.bypassRoutes);
1588 /* Delete index dict */
1589 xbt_dict_free(&(routing->generic_routing.to_index));
1590 /* Delete dictionary index dict, predecessor and links table */
1591 xbt_free(routing->predecessor_table);
1592 /* Delete structure */
1597 static void *model_floyd_create(void)
1599 routing_component_floyd_t new_component =
1600 xbt_new0(s_routing_component_floyd_t, 1);
1601 new_component->generic_routing.set_processing_unit =
1602 generic_set_processing_unit;
1603 new_component->generic_routing.set_autonomous_system =
1604 generic_set_autonomous_system;
1605 new_component->generic_routing.set_route = model_floyd_set_route;
1606 new_component->generic_routing.set_ASroute = model_floyd_set_route;
1607 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1608 new_component->generic_routing.get_route = floyd_get_route;
1609 new_component->generic_routing.get_latency = generic_get_link_latency;
1610 new_component->generic_routing.get_onelink_routes =
1611 floyd_get_onelink_routes;
1612 new_component->generic_routing.get_bypass_route =
1613 generic_get_bypassroute;
1614 new_component->generic_routing.finalize = floyd_finalize;
1615 new_component->generic_routing.to_index = xbt_dict_new();
1616 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1617 new_component->generic_routing.get_network_element_type = get_network_element_type;
1618 return new_component;
1621 static void model_floyd_load(void)
1623 /* use "surfxml_add_callback" to add a parse function call */
1626 static void model_floyd_unload(void)
1628 /* use "surfxml_del_callback" to remove a parse function call */
1631 static void model_floyd_end(void)
1634 routing_component_floyd_t routing =
1635 ((routing_component_floyd_t) current_routing);
1637 unsigned int i, j, a, b, c;
1639 /* set the size of table routing */
1640 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1642 if(!routing->link_table)
1644 /* Create Cost, Predecessor and Link tables */
1645 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1646 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1647 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1649 /* Initialize costs and predecessors */
1650 for (i = 0; i < table_size; i++)
1651 for (j = 0; j < table_size; j++) {
1652 TO_FLOYD_COST(i, j) = DBL_MAX;
1653 TO_FLOYD_PRED(i, j) = -1;
1654 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1658 /* Add the loopback if needed */
1659 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1660 for (i = 0; i < table_size; i++) {
1661 route_extended_t e_route = TO_FLOYD_LINK(i, i);
1663 e_route = xbt_new0(s_route_extended_t, 1);
1664 e_route->src_gateway = NULL;
1665 e_route->dst_gateway = NULL;
1666 e_route->generic_route.link_list =
1667 xbt_dynar_new(global_routing->size_of_link, NULL);
1668 xbt_dynar_push(e_route->generic_route.link_list,
1669 &global_routing->loopback);
1670 TO_FLOYD_LINK(i, i) = e_route;
1671 TO_FLOYD_PRED(i, i) = i;
1672 TO_FLOYD_COST(i, i) = 1;
1676 /* Calculate path costs */
1677 for (c = 0; c < table_size; c++) {
1678 for (a = 0; a < table_size; a++) {
1679 for (b = 0; b < table_size; b++) {
1680 if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
1681 if (TO_FLOYD_COST(a, b) == DBL_MAX ||
1682 (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
1683 TO_FLOYD_COST(a, b))) {
1684 TO_FLOYD_COST(a, b) =
1685 TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
1686 TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
1694 static void model_floyd_set_route(routing_component_t rc, const char *src,
1695 const char *dst, name_route_extended_t route)
1697 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1699 /* set the size of table routing */
1700 size_t table_size = xbt_dict_length(rc->to_index);
1701 int *src_id, *dst_id;
1704 src_id = xbt_dict_get_or_null(rc->to_index, src);
1705 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1707 if(!routing->link_table)
1709 /* Create Cost, Predecessor and Link tables */
1710 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1711 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1712 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1714 /* Initialize costs and predecessors */
1715 for (i = 0; i < table_size; i++)
1716 for (j = 0; j < table_size; j++) {
1717 TO_FLOYD_COST(i, j) = DBL_MAX;
1718 TO_FLOYD_PRED(i, j) = -1;
1719 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1723 if(TO_FLOYD_LINK(*src_id, *dst_id))
1725 if(!route->dst_gateway && !route->src_gateway)
1726 XBT_DEBUG("See Route from \"%s\" to \"%s\"", src, dst);
1728 XBT_DEBUG("See ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1729 route->src_gateway, dst, route->dst_gateway);
1732 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1733 xbt_dynar_foreach(route->generic_route.link_list,cpt,link_name)
1735 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1736 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1737 xbt_dynar_push(link_route_to_test,&link);
1739 xbt_assert2(!xbt_dynar_compare(
1740 (void*)TO_FLOYD_LINK(*src_id, *dst_id)->generic_route.link_list,
1741 (void*)link_route_to_test,
1742 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1743 "The route between \"%s\" and \"%s\" already exists", src,dst);
1744 xbt_free(link_route_to_test);
1748 if(!route->dst_gateway && !route->src_gateway)
1749 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
1751 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1752 route->src_gateway, dst, route->dst_gateway);
1754 TO_FLOYD_LINK(*src_id, *dst_id) =
1755 generic_new_extended_route(rc->hierarchy, route, 1);
1756 TO_FLOYD_PRED(*src_id, *dst_id) = *src_id;
1757 TO_FLOYD_COST(*src_id, *dst_id) =
1758 ((TO_FLOYD_LINK(*src_id, *dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1761 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1762 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1764 if(TO_FLOYD_LINK(*dst_id, *src_id))
1766 if(!route->dst_gateway && !route->src_gateway)
1767 XBT_DEBUG("See Route from \"%s\" to \"%s\"", dst, src);
1769 XBT_DEBUG("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1770 route->src_gateway, src, route->dst_gateway);
1773 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1774 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1776 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1777 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1778 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1779 xbt_dynar_push(link_route_to_test,&link);
1781 xbt_assert2(!xbt_dynar_compare(
1782 (void*)TO_FLOYD_LINK(*dst_id, *src_id)->generic_route.link_list,
1783 (void*)link_route_to_test,
1784 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1785 "The route between \"%s\" and \"%s\" already exists", src,dst);
1786 xbt_free(link_route_to_test);
1790 if(route->dst_gateway && route->src_gateway)
1792 char *gw_src = xbt_strdup(route->src_gateway);
1793 char *gw_dst = xbt_strdup(route->dst_gateway);
1794 route->src_gateway = gw_dst;
1795 route->dst_gateway = gw_src;
1798 if(!route->dst_gateway && !route->src_gateway)
1799 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
1801 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1802 route->src_gateway, src, route->dst_gateway);
1804 TO_FLOYD_LINK(*dst_id, *src_id) =
1805 generic_new_extended_route(rc->hierarchy, route, 0);
1806 TO_FLOYD_PRED(*dst_id, *src_id) = *dst_id;
1807 TO_FLOYD_COST(*dst_id, *src_id) =
1808 ((TO_FLOYD_LINK(*dst_id, *src_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1813 /* ************************************************************************** */
1814 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1817 s_routing_component_t generic_routing;
1818 xbt_graph_t route_graph; /* xbt_graph */
1819 xbt_dict_t graph_node_map; /* map */
1820 xbt_dict_t route_cache; /* use in cache mode */
1822 } s_routing_component_dijkstra_t, *routing_component_dijkstra_t;
1825 typedef struct graph_node_data {
1827 int graph_id; /* used for caching internal graph id's */
1828 } s_graph_node_data_t, *graph_node_data_t;
1830 typedef struct graph_node_map_element {
1832 } s_graph_node_map_element_t, *graph_node_map_element_t;
1834 typedef struct route_cache_element {
1837 } s_route_cache_element_t, *route_cache_element_t;
1839 /* Free functions */
1841 static void route_cache_elem_free(void *e)
1843 route_cache_element_t elm = (route_cache_element_t) e;
1845 xbt_free(elm->pred_arr);
1850 static void graph_node_map_elem_free(void *e)
1852 graph_node_map_element_t elm = (graph_node_map_element_t) e;
1858 static void graph_edge_data_free(void *e)
1860 route_extended_t e_route = (route_extended_t) e;
1862 xbt_dynar_free(&(e_route->generic_route.link_list));
1863 if (e_route->src_gateway)
1864 xbt_free(e_route->src_gateway);
1865 if (e_route->dst_gateway)
1866 xbt_free(e_route->dst_gateway);
1871 /* Utility functions */
1873 static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc,
1874 int id, int graph_id)
1876 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1877 xbt_node_t node = NULL;
1878 graph_node_data_t data = NULL;
1879 graph_node_map_element_t elm = NULL;
1881 data = xbt_new0(struct graph_node_data, 1);
1883 data->graph_id = graph_id;
1884 node = xbt_graph_new_node(routing->route_graph, data);
1886 elm = xbt_new0(struct graph_node_map_element, 1);
1888 xbt_dict_set_ext(routing->graph_node_map, (char *) (&id), sizeof(int),
1889 (xbt_set_elm_t) elm, &graph_node_map_elem_free);
1894 static graph_node_map_element_t
1895 graph_node_map_search(routing_component_dijkstra_t rc, int id)
1897 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1898 graph_node_map_element_t elm = (graph_node_map_element_t)
1899 xbt_dict_get_or_null_ext(routing->graph_node_map,
1907 static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id,
1908 int dst_id, route_extended_t e_route)
1910 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1911 XBT_DEBUG("Load Route from \"%d\" to \"%d\"", src_id, dst_id);
1912 xbt_node_t src = NULL;
1913 xbt_node_t dst = NULL;
1915 graph_node_map_element_t src_elm = (graph_node_map_element_t)
1916 xbt_dict_get_or_null_ext(routing->graph_node_map,
1919 graph_node_map_element_t dst_elm = (graph_node_map_element_t)
1920 xbt_dict_get_or_null_ext(routing->graph_node_map,
1926 src = src_elm->node;
1929 dst = dst_elm->node;
1931 /* add nodes if they don't exist in the graph */
1932 if (src_id == dst_id && src == NULL && dst == NULL) {
1933 src = route_graph_new_node(rc, src_id, -1);
1937 src = route_graph_new_node(rc, src_id, -1);
1940 dst = route_graph_new_node(rc, dst_id, -1);
1944 /* add link as edge to graph */
1945 xbt_graph_new_edge(routing->route_graph, src, dst, e_route);
1948 static void add_loopback_dijkstra(routing_component_dijkstra_t rc)
1950 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1952 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1954 xbt_node_t node = NULL;
1955 unsigned int cursor2;
1956 xbt_dynar_foreach(nodes, cursor2, node) {
1957 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1958 xbt_edge_t edge = NULL;
1959 unsigned int cursor;
1962 xbt_dynar_foreach(out_edges, cursor, edge) {
1963 xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1964 if (other_node == node) {
1971 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
1972 e_route->src_gateway = NULL;
1973 e_route->dst_gateway = NULL;
1974 e_route->generic_route.link_list =
1975 xbt_dynar_new(global_routing->size_of_link, NULL);
1976 xbt_dynar_push(e_route->generic_route.link_list,
1977 &global_routing->loopback);
1978 xbt_graph_new_edge(routing->route_graph, node, node, e_route);
1983 /* Business methods */
1984 static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
1986 xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
1989 static route_extended_t dijkstra_get_route(routing_component_t rc,
1993 xbt_assert1(rc && src
1995 "Invalid params for \"get_route\" function at AS \"%s\"",
1998 /* set utils vars */
1999 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2001 generic_src_dst_check(rc, src, dst);
2002 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
2003 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
2006 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
2009 /* create a result route */
2010 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
2011 new_e_route->generic_route.link_list =
2012 xbt_dynar_new(global_routing->size_of_link, NULL);
2013 new_e_route->src_gateway = NULL;
2014 new_e_route->dst_gateway = NULL;
2016 int *pred_arr = NULL;
2017 int src_node_id = 0;
2018 int dst_node_id = 0;
2021 route_extended_t e_route;
2025 xbt_dynar_t links = NULL;
2026 route_cache_element_t elm = NULL;
2027 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
2029 /* Use the graph_node id mapping set to quickly find the nodes */
2030 graph_node_map_element_t src_elm =
2031 graph_node_map_search(routing, *src_id);
2032 graph_node_map_element_t dst_elm =
2033 graph_node_map_search(routing, *dst_id);
2034 xbt_assert2(src_elm != NULL
2035 && dst_elm != NULL, "src %d or dst %d does not exist",
2037 src_node_id = ((graph_node_data_t)
2038 xbt_graph_node_get_data(src_elm->node))->graph_id;
2039 dst_node_id = ((graph_node_data_t)
2040 xbt_graph_node_get_data(dst_elm->node))->graph_id;
2042 /* if the src and dst are the same *//* fixed, missing in the previous version */
2043 if (src_node_id == dst_node_id) {
2045 xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
2046 xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
2048 xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v);
2050 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
2053 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
2055 links = e_route->generic_route.link_list;
2056 xbt_dynar_foreach(links, cpt, link) {
2057 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
2063 if (routing->cached) {
2064 /*check if there is a cached predecessor list avail */
2065 elm = (route_cache_element_t)
2066 xbt_dict_get_or_null_ext(routing->route_cache, (char *) (&src_id),
2070 if (elm) { /* cached mode and cache hit */
2071 pred_arr = elm->pred_arr;
2072 } else { /* not cached mode or cache miss */
2073 double *cost_arr = NULL;
2074 xbt_heap_t pqueue = NULL;
2077 int nr_nodes = xbt_dynar_length(nodes);
2078 cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
2079 pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
2080 pqueue = xbt_heap_new(nr_nodes, xbt_free);
2083 cost_arr[src_node_id] = 0.0;
2085 for (i = 0; i < nr_nodes; i++) {
2086 if (i != src_node_id) {
2087 cost_arr[i] = DBL_MAX;
2092 /* initialize priority queue */
2093 nodeid = xbt_new0(int, 1);
2095 xbt_heap_push(pqueue, nodeid, cost_arr[i]);
2099 /* apply dijkstra using the indexes from the graph's node array */
2100 while (xbt_heap_size(pqueue) > 0) {
2101 int *v_id = xbt_heap_pop(pqueue);
2102 xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
2103 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
2104 xbt_edge_t edge = NULL;
2105 unsigned int cursor;
2107 xbt_dynar_foreach(out_edges, cursor, edge) {
2108 xbt_node_t u_node = xbt_graph_edge_get_target(edge);
2109 graph_node_data_t data = xbt_graph_node_get_data(u_node);
2110 int u_id = data->graph_id;
2111 route_extended_t tmp_e_route =
2112 (route_extended_t) xbt_graph_edge_get_data(edge);
2113 int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */
2115 if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
2116 pred_arr[u_id] = *v_id;
2117 cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
2118 nodeid = xbt_new0(int, 1);
2120 xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
2124 /* free item popped from pqueue */
2129 xbt_heap_free(pqueue);
2132 /* compose route path with links */
2133 char *gw_src = NULL, *gw_dst =
2134 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
2136 for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
2137 xbt_node_t node_pred_v =
2138 xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
2139 xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
2141 xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
2143 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
2146 prev_gw_src = gw_src;
2147 prev_gw_dst = gw_dst;
2149 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
2150 gw_src = e_route->src_gateway;
2151 gw_dst = e_route->dst_gateway;
2153 if (v == dst_node_id)
2156 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
2157 && strcmp(gw_dst, prev_gw_src)) {
2158 xbt_dynar_t e_route_as_to_as =
2159 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
2160 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
2161 gw_dst, prev_gw_src);
2162 links = e_route_as_to_as;
2164 xbt_dynar_foreach(links, cpt, link) {
2165 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
2171 links = e_route->generic_route.link_list;
2172 xbt_dynar_foreach(links, cpt, link) {
2173 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
2178 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
2179 new_e_route->src_gateway = xbt_strdup(gw_src);
2180 new_e_route->dst_gateway = xbt_strdup(first_gw);
2183 if (routing->cached && elm == NULL) {
2184 /* add to predecessor list of the current src-host to cache */
2185 elm = xbt_new0(struct route_cache_element, 1);
2186 elm->pred_arr = pred_arr;
2188 xbt_dict_set_ext(routing->route_cache, (char *) (&src_id), sizeof(int),
2189 (xbt_set_elm_t) elm, &route_cache_elem_free);
2192 if (!routing->cached)
2198 static void dijkstra_finalize(routing_component_t rc)
2200 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2203 xbt_graph_free_graph(routing->route_graph, &xbt_free,
2204 &graph_edge_data_free, &xbt_free);
2205 xbt_dict_free(&routing->graph_node_map);
2206 if (routing->cached)
2207 xbt_dict_free(&routing->route_cache);
2208 /* Delete bypass dict */
2209 xbt_dict_free(&routing->generic_routing.bypassRoutes);
2210 /* Delete index dict */
2211 xbt_dict_free(&(routing->generic_routing.to_index));
2212 /* Delete structure */
2217 /* Creation routing model functions */
2219 static void *model_dijkstra_both_create(int cached)
2221 routing_component_dijkstra_t new_component =
2222 xbt_new0(s_routing_component_dijkstra_t, 1);
2223 new_component->generic_routing.set_processing_unit =
2224 generic_set_processing_unit;
2225 new_component->generic_routing.set_autonomous_system =
2226 generic_set_autonomous_system;
2227 new_component->generic_routing.set_route = model_dijkstra_both_set_route;
2228 new_component->generic_routing.set_ASroute = model_dijkstra_both_set_route; //TODO
2229 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
2230 new_component->generic_routing.get_route = dijkstra_get_route;
2231 new_component->generic_routing.get_latency = generic_get_link_latency;
2232 new_component->generic_routing.get_onelink_routes =
2233 dijkstra_get_onelink_routes;
2234 new_component->generic_routing.get_bypass_route =
2235 generic_get_bypassroute;
2236 new_component->generic_routing.finalize = dijkstra_finalize;
2237 new_component->cached = cached;
2238 new_component->generic_routing.to_index = xbt_dict_new();
2239 new_component->generic_routing.bypassRoutes = xbt_dict_new();
2240 new_component->generic_routing.get_network_element_type = get_network_element_type;
2241 return new_component;
2244 static void *model_dijkstra_create(void)
2246 return model_dijkstra_both_create(0);
2249 static void *model_dijkstracache_create(void)
2251 return model_dijkstra_both_create(1);
2254 static void model_dijkstra_both_load(void)
2256 /* use "surfxml_add_callback" to add a parse function call */
2259 static void model_dijkstra_both_unload(void)
2261 /* use "surfxml_del_callback" to remove a parse function call */
2264 static void model_dijkstra_both_end(void)
2266 routing_component_dijkstra_t routing =
2267 (routing_component_dijkstra_t) current_routing;
2269 xbt_node_t node = NULL;
2270 unsigned int cursor2;
2271 xbt_dynar_t nodes = NULL;
2273 /* Create the topology graph */
2274 if(!routing->route_graph)
2275 routing->route_graph = xbt_graph_new_graph(1, NULL);
2276 if(!routing->graph_node_map)
2277 routing->graph_node_map = xbt_dict_new();
2279 if (routing->cached && !routing->route_cache)
2280 routing->route_cache = xbt_dict_new();
2282 /* Add the loopback if needed */
2283 if (current_routing->hierarchy == SURF_ROUTING_BASE)
2284 add_loopback_dijkstra(routing);
2286 /* initialize graph indexes in nodes after graph has been built */
2287 nodes = xbt_graph_get_nodes(routing->route_graph);
2289 xbt_dynar_foreach(nodes, cursor2, node) {
2290 graph_node_data_t data = xbt_graph_node_get_data(node);
2291 data->graph_id = cursor2;
2295 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
2296 const char *dst, name_route_extended_t route)
2298 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2299 int *src_id, *dst_id;
2300 src_id = xbt_dict_get_or_null(rc->to_index, src);
2301 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
2303 /* Create the topology graph */
2304 if(!routing->route_graph)
2305 routing->route_graph = xbt_graph_new_graph(1, NULL);
2306 if(!routing->graph_node_map)
2307 routing->graph_node_map = xbt_dict_new();
2309 if (routing->cached && !routing->route_cache)
2310 routing->route_cache = xbt_dict_new();
2312 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
2313 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
2314 xbt_die("Route symmetrical not supported on model dijkstra");
2316 if(!route->dst_gateway && !route->src_gateway)
2317 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
2319 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
2320 route->src_gateway, dst, route->dst_gateway);
2322 route_extended_t e_route =
2323 generic_new_extended_route(current_routing->hierarchy, route, 1);
2324 route_new_dijkstra(routing, *src_id, *dst_id, e_route);
2327 #ifdef HAVE_PCRE_LIB
2328 /* ************************************************** */
2329 /* ************** RULE-BASED ROUTING **************** */
2331 /* Routing model structure */
2334 s_routing_component_t generic_routing;
2335 xbt_dict_t dict_processing_units;
2336 xbt_dict_t dict_autonomous_systems;
2337 xbt_dynar_t list_route;
2338 xbt_dynar_t list_ASroute;
2339 } s_routing_component_rulebased_t, *routing_component_rulebased_t;
2341 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
2342 typedef struct s_rule_route_extended s_rule_route_extended_t,
2343 *rule_route_extended_t;
2345 struct s_rule_route {
2346 xbt_dynar_t re_str_link; // dynar of char*
2351 struct s_rule_route_extended {
2352 s_rule_route_t generic_rule_route;
2353 char *re_src_gateway;
2354 char *re_dst_gateway;
2357 static void rule_route_free(void *e)
2359 rule_route_t *elem = (rule_route_t *) (e);
2361 xbt_dynar_free(&(*elem)->re_str_link);
2362 pcre_free((*elem)->re_src);
2363 pcre_free((*elem)->re_dst);
2369 static void rule_route_extended_free(void *e)
2371 rule_route_extended_t *elem = (rule_route_extended_t *) e;
2373 xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link);
2374 pcre_free((*elem)->generic_rule_route.re_src);
2375 pcre_free((*elem)->generic_rule_route.re_dst);
2376 xbt_free((*elem)->re_src_gateway);
2377 xbt_free((*elem)->re_dst_gateway);
2382 /* Parse routing model functions */
2384 static void model_rulebased_set_processing_unit(routing_component_t rc,
2387 routing_component_rulebased_t routing =
2388 (routing_component_rulebased_t) rc;
2389 xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
2392 static void model_rulebased_set_autonomous_system(routing_component_t rc,
2395 routing_component_rulebased_t routing =
2396 (routing_component_rulebased_t) rc;
2397 xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
2401 static void model_rulebased_set_route(routing_component_t rc,
2402 const char *src, const char *dst,
2403 name_route_extended_t route)
2405 routing_component_rulebased_t routing =
2406 (routing_component_rulebased_t) rc;
2407 rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
2410 ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL);
2411 xbt_assert3(ruleroute->re_src,
2412 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2413 erroffset, src, error);
2414 ruleroute->re_dst = pcre_compile(dst, 0, &error, &erroffset, NULL);
2415 xbt_assert3(ruleroute->re_src,
2416 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2417 erroffset, dst, error);
2418 ruleroute->re_str_link = route->generic_route.link_list;
2419 xbt_dynar_push(routing->list_route, &ruleroute);
2423 static void model_rulebased_set_ASroute(routing_component_t rc,
2424 const char *src, const char *dst,
2425 name_route_extended_t route)
2427 routing_component_rulebased_t routing =
2428 (routing_component_rulebased_t) rc;
2429 rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
2432 ruleroute_e->generic_rule_route.re_src =
2433 pcre_compile(src, 0, &error, &erroffset, NULL);
2434 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2435 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2436 erroffset, src, error);
2437 ruleroute_e->generic_rule_route.re_dst =
2438 pcre_compile(dst, 0, &error, &erroffset, NULL);
2439 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2440 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2441 erroffset, dst, error);
2442 ruleroute_e->generic_rule_route.re_str_link =
2443 route->generic_route.link_list;
2444 ruleroute_e->re_src_gateway = route->src_gateway;
2445 ruleroute_e->re_dst_gateway = route->dst_gateway;
2446 xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
2447 // xbt_free(route->src_gateway);
2448 // xbt_free(route->dst_gateway);
2452 static void model_rulebased_set_bypassroute(routing_component_t rc,
2455 route_extended_t e_route)
2457 xbt_die("bypass routing not supported for Route-Based model");
2460 #define BUFFER_SIZE 4096 /* result buffer size */
2461 #define OVECCOUNT 30 /* should be a multiple of 3 */
2463 static char *remplace(char *value, const char **src_list, int src_size,
2464 const char **dst_list, int dst_size)
2467 char result_result[BUFFER_SIZE];
2468 int i_result_buffer;
2469 int value_length = (int) strlen(value);
2473 i_result_buffer = 0;
2475 if (value[i] == '$') {
2479 int number_length = 0;
2480 while ('0' <= value[i + number_length]
2481 && value[i + number_length] <= '9') {
2484 xbt_assert2(number_length != 0,
2485 "bad string parameter, no number indication, at offset: %d (\"%s\")",
2489 number = atoi(value + i);
2490 i = i + number_length;
2491 xbt_assert2(i + 2 < value_length,
2492 "bad string parameter, too few chars, at offset: %d (\"%s\")",
2495 // solve the indication
2496 const char **param_list;
2498 if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') {
2499 param_list = src_list;
2500 param_size = src_size;
2501 } else if (value[i] == 'd' && value[i + 1] == 's'
2502 && value[i + 2] == 't') {
2503 param_list = dst_list;
2504 param_size = dst_size;
2506 xbt_die("bad string parameter, support only \"src\" and \"dst\", "
2507 "at offset: %d (\"%s\")", i, value);
2511 xbt_assert4(param_size >= number,
2512 "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",
2513 i, value, param_size, number);
2515 const char *param = param_list[number];
2516 int size = strlen(param);
2518 for (cp = 0; cp < size; cp++) {
2519 result_result[i_result_buffer] = param[cp];
2521 if (i_result_buffer >= BUFFER_SIZE)
2525 result_result[i_result_buffer] = value[i];
2530 } while (i < value_length && i_result_buffer < BUFFER_SIZE);
2532 xbt_assert2(i_result_buffer < BUFFER_SIZE,
2533 "solving string \"%s\", small buffer size (%d)", value,
2535 result_result[i_result_buffer] = 0;
2536 return xbt_strdup(result_result);
2539 static route_extended_t rulebased_get_route(routing_component_t rc,
2542 static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
2544 xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
2545 routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
2547 xbt_dict_cursor_t c1 = NULL;
2551 char *router = NULL;
2552 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2553 if (strstr (k1, "router")){
2558 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2561 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2562 route_extended_t route = rulebased_get_route (rc, router, k1);
2564 int number_of_links = xbt_dynar_length(route->generic_route.link_list);
2565 if (number_of_links != 3) {
2566 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2570 xbt_dynar_get_cpy (route->generic_route.link_list, 2, &link_ptr);
2571 onelink_t onelink = xbt_new0 (s_onelink_t, 1);
2572 onelink->src = xbt_strdup (k1);
2573 onelink->dst = xbt_strdup (router);
2574 onelink->link_ptr = link_ptr;
2575 xbt_dynar_push (ret, &onelink);
2580 /* Business methods */
2581 static route_extended_t rulebased_get_route(routing_component_t rc,
2585 xbt_assert1(rc && src
2587 "Invalid params for \"get_route\" function at AS \"%s\"",
2590 /* set utils vars */
2591 routing_component_rulebased_t routing =
2592 (routing_component_rulebased_t) rc;
2594 int are_processing_units=0;
2595 xbt_dynar_t rule_list;
2596 if (xbt_dict_get_or_null(routing->dict_processing_units, src)
2597 && xbt_dict_get_or_null(routing->dict_processing_units, dst)) {
2598 are_processing_units = 1;
2599 rule_list = routing->list_route;
2600 } else if (xbt_dict_get_or_null(routing->dict_autonomous_systems, src)
2601 && xbt_dict_get_or_null(routing->dict_autonomous_systems,
2603 are_processing_units = 0;
2604 rule_list = routing->list_ASroute;
2606 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found in "
2607 "the local table", src, dst);
2611 int src_length = (int) strlen(src);
2612 int dst_length = (int) strlen(dst);
2614 xbt_dynar_t links_list =
2615 xbt_dynar_new(global_routing->size_of_link, NULL);
2617 rule_route_t ruleroute;
2619 int ovector_src[OVECCOUNT];
2620 int ovector_dst[OVECCOUNT];
2621 const char **list_src = NULL;
2622 const char **list_dst = NULL;
2624 xbt_dynar_foreach(rule_list, cpt, ruleroute) {
2626 pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0,
2627 ovector_src, OVECCOUNT);
2630 pcre_exec(ruleroute->re_dst, NULL, dst, dst_length, 0, 0,
2631 ovector_dst, OVECCOUNT);
2633 res = pcre_get_substring_list(src, ovector_src, rc_src, &list_src);
2634 xbt_assert1(!res, "error solving substring list for src \"%s\"", src);
2635 res = pcre_get_substring_list(dst, ovector_dst, rc_dst, &list_dst);
2636 xbt_assert1(!res, "error solving substring list for src \"%s\"", dst);
2638 xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) {
2639 char *new_link_name =
2640 remplace(link_name, list_src, rc_src, list_dst, rc_dst);
2642 xbt_dict_get_or_null(surf_network_model->resource_set,
2645 xbt_dynar_push(links_list, &link);
2647 THROW1(mismatch_error, 0, "Link %s not found", new_link_name);
2648 xbt_free(new_link_name);
2652 if (rc_src >= 0 && rc_dst >= 0)
2656 route_extended_t new_e_route = NULL;
2657 if (rc_src >= 0 && rc_dst >= 0) {
2658 new_e_route = xbt_new0(s_route_extended_t, 1);
2659 new_e_route->generic_route.link_list = links_list;
2660 } else if (!strcmp(src, dst) && are_processing_units) {
2661 new_e_route = xbt_new0(s_route_extended_t, 1);
2662 xbt_dynar_push(links_list, &(global_routing->loopback));
2663 new_e_route->generic_route.link_list = links_list;
2665 xbt_dynar_free(&link_list);
2668 if (!are_processing_units && new_e_route) {
2669 rule_route_extended_t ruleroute_extended =
2670 (rule_route_extended_t) ruleroute;
2671 new_e_route->src_gateway =
2672 remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
2674 new_e_route->dst_gateway =
2675 remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
2680 pcre_free_substring_list(list_src);
2682 pcre_free_substring_list(list_dst);
2687 static route_extended_t rulebased_get_bypass_route(routing_component_t rc,
2694 static void rulebased_finalize(routing_component_t rc)
2696 routing_component_rulebased_t routing =
2697 (routing_component_rulebased_t) rc;
2699 xbt_dict_free(&routing->dict_processing_units);
2700 xbt_dict_free(&routing->dict_autonomous_systems);
2701 xbt_dynar_free(&routing->list_route);
2702 xbt_dynar_free(&routing->list_ASroute);
2703 /* Delete structure */
2708 /* Creation routing model functions */
2709 static void *model_rulebased_create(void)
2711 routing_component_rulebased_t new_component =
2712 xbt_new0(s_routing_component_rulebased_t, 1);
2713 new_component->generic_routing.set_processing_unit =
2714 model_rulebased_set_processing_unit;
2715 new_component->generic_routing.set_autonomous_system =
2716 model_rulebased_set_autonomous_system;
2717 new_component->generic_routing.set_route = model_rulebased_set_route;
2718 new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
2719 new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
2720 new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
2721 new_component->generic_routing.get_route = rulebased_get_route;
2722 new_component->generic_routing.get_latency = generic_get_link_latency;
2723 new_component->generic_routing.get_bypass_route = rulebased_get_bypass_route;
2724 new_component->generic_routing.finalize = rulebased_finalize;
2725 new_component->generic_routing.get_network_element_type = get_network_element_type;
2726 /* initialization of internal structures */
2727 new_component->dict_processing_units = xbt_dict_new();
2728 new_component->dict_autonomous_systems = xbt_dict_new();
2729 new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
2730 new_component->list_ASroute =
2731 xbt_dynar_new(sizeof(rule_route_extended_t),
2732 &rule_route_extended_free);
2733 return new_component;
2736 static void model_rulebased_load(void)
2738 /* use "surfxml_add_callback" to add a parse function call */
2741 static void model_rulebased_unload(void)
2743 /* use "surfxml_del_callback" to remove a parse function call */
2746 static void model_rulebased_end(void)
2750 #endif /* HAVE_PCRE_LIB */
2752 /* ************************************************************************** */
2753 /* ******************************* NO ROUTING ******************************* */
2755 /* Routing model structure */
2757 s_routing_component_t generic_routing;
2758 } s_routing_component_none_t, *routing_component_none_t;
2760 /* Business methods */
2761 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc)
2766 static route_extended_t none_get_route(routing_component_t rc,
2767 const char *src, const char *dst)
2772 static route_extended_t none_get_bypass_route(routing_component_t rc,
2779 static void none_finalize(routing_component_t rc)
2784 static void none_set_processing_unit(routing_component_t rc,
2789 static void none_set_autonomous_system(routing_component_t rc,
2794 /* Creation routing model functions */
2795 static void *model_none_create(void)
2797 routing_component_none_t new_component =
2798 xbt_new0(s_routing_component_none_t, 1);
2799 new_component->generic_routing.set_processing_unit =
2800 none_set_processing_unit;
2801 new_component->generic_routing.set_autonomous_system =
2802 none_set_autonomous_system;
2803 new_component->generic_routing.set_route = NULL;
2804 new_component->generic_routing.set_ASroute = NULL;
2805 new_component->generic_routing.set_bypassroute = NULL;
2806 new_component->generic_routing.get_route = none_get_route;
2807 new_component->generic_routing.get_onelink_routes =
2808 none_get_onelink_routes;
2809 new_component->generic_routing.get_bypass_route = none_get_bypass_route;
2810 new_component->generic_routing.finalize = none_finalize;
2811 return new_component;
2814 static void model_none_load(void)
2818 static void model_none_unload(void)
2822 static void model_none_end(void)
2826 /* ************************************************** */
2827 /* ********** PATERN FOR NEW ROUTING **************** */
2829 /* The minimal configuration of a new routing model need the next functions,
2830 * also you need to set at the start of the file, the new model in the model
2831 * list. Remember keep the null ending of the list.
2833 /*** Routing model structure ***/
2835 // s_routing_component_t generic_routing;
2836 // /* things that your routing model need */
2837 // } s_routing_component_NEW_t,*routing_component_NEW_t;
2839 /*** Parse routing model functions ***/
2840 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
2841 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
2842 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
2843 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
2844 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
2846 /*** Business methods ***/
2847 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2848 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2849 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
2851 /*** Creation routing model functions ***/
2852 // static void* model_NEW_create(void) {
2853 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
2854 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
2855 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
2856 // new_component->generic_routing.set_route = model_NEW_set_route;
2857 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
2858 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
2859 // new_component->generic_routing.get_route = NEW_get_route;
2860 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
2861 // new_component->generic_routing.finalize = NEW_finalize;
2862 // /* initialization of internal structures */
2863 // return new_component;
2864 // } /* mandatory */
2865 // static void model_NEW_load(void) {} /* mandatory */
2866 // static void model_NEW_unload(void) {} /* mandatory */
2867 // static void model_NEW_end(void) {} /* mandatory */
2869 /* ************************************************************************** */
2870 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
2872 static void generic_set_processing_unit(routing_component_t rc,
2875 XBT_DEBUG("Load process unit \"%s\"", name);
2876 int *id = xbt_new0(int, 1);
2877 xbt_dict_t _to_index;
2878 _to_index = current_routing->to_index;
2879 *id = xbt_dict_length(_to_index);
2880 xbt_dict_set(_to_index, name, id, xbt_free);
2883 static void generic_set_autonomous_system(routing_component_t rc,
2886 XBT_DEBUG("Load Autonomous system \"%s\"", name);
2887 int *id = xbt_new0(int, 1);
2888 xbt_dict_t _to_index;
2889 _to_index = current_routing->to_index;
2890 *id = xbt_dict_length(_to_index);
2891 xbt_dict_set(_to_index, name, id, xbt_free);
2894 static int surf_pointer_resource_cmp(const void *a, const void *b)
2899 static int surf_link_resource_cmp(const void *a, const void *b)
2901 return !!memcmp(a,b,global_routing->size_of_link);
2904 static void generic_set_bypassroute(routing_component_t rc,
2905 const char *src, const char *dst,
2906 route_extended_t e_route)
2908 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
2909 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2912 route_name = bprintf("%s#%s", src, dst);
2913 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2914 "Invalid count of links, must be greater than zero (%s,%s)",
2916 xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
2917 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
2918 src, e_route->src_gateway, dst, e_route->dst_gateway);
2920 route_extended_t new_e_route =
2921 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
2922 xbt_dynar_free(&(e_route->generic_route.link_list));
2925 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
2926 (void (*)(void *)) generic_free_extended_route);
2927 xbt_free(route_name);
2930 /* ************************************************************************** */
2931 /* *********************** GENERIC BUSINESS METHODS ************************* */
2933 static double generic_get_link_latency(routing_component_t rc,
2934 const char *src, const char *dst)
2936 route_extended_t route = rc->get_route(rc,src,dst);
2939 double latency = 0.0;
2941 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
2942 latency += get_link_latency(link);
2944 generic_free_extended_route(route);
2948 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
2950 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
2953 static route_extended_t generic_get_bypassroute(routing_component_t rc,
2957 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2958 routing_component_t src_as, dst_as;
2959 int index_src, index_dst;
2960 xbt_dynar_t path_src = NULL;
2961 xbt_dynar_t path_dst = NULL;
2962 routing_component_t current = NULL;
2963 routing_component_t *current_src = NULL;
2964 routing_component_t *current_dst = NULL;
2966 /* (1) find the as where the src and dst are located */
2967 src_as = ((network_element_info_t)
2968 xbt_dict_get_or_null(global_routing->where_network_elements,
2969 src))->rc_component;
2970 dst_as = ((network_element_info_t)
2971 xbt_dict_get_or_null(global_routing->where_network_elements,
2972 dst))->rc_component;
2975 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
2978 /* (2) find the path to the root routing component */
2979 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
2981 while (current != NULL) {
2982 xbt_dynar_push(path_src, ¤t);
2983 current = current->routing_father;
2985 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
2987 while (current != NULL) {
2988 xbt_dynar_push(path_dst, ¤t);
2989 current = current->routing_father;
2992 /* (3) find the common father */
2993 index_src = path_src->used - 1;
2994 index_dst = path_dst->used - 1;
2995 current_src = xbt_dynar_get_ptr(path_src, index_src);
2996 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2997 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
2998 routing_component_t *tmp_src, *tmp_dst;
2999 tmp_src = xbt_dynar_pop_ptr(path_src);
3000 tmp_dst = xbt_dynar_pop_ptr(path_dst);
3003 current_src = xbt_dynar_get_ptr(path_src, index_src);
3004 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
3007 int max_index_src = path_src->used - 1;
3008 int max_index_dst = path_dst->used - 1;
3010 int max_index = max(max_index_src, max_index_dst);
3013 route_extended_t e_route_bypass = NULL;
3015 for (max = 0; max <= max_index; max++) {
3016 for (i = 0; i < max; i++) {
3017 if (i <= max_index_src && max <= max_index_dst) {
3018 char *route_name = bprintf("%s#%s",
3019 (*(routing_component_t *)
3021 (path_src, i)))->name,
3022 (*(routing_component_t *)
3024 (path_dst, max)))->name);
3026 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
3027 xbt_free(route_name);
3031 if (max <= max_index_src && i <= max_index_dst) {
3032 char *route_name = bprintf("%s#%s",
3033 (*(routing_component_t *)
3035 (path_src, max)))->name,
3036 (*(routing_component_t *)
3038 (path_dst, i)))->name);
3040 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
3041 xbt_free(route_name);
3050 if (max <= max_index_src && max <= max_index_dst) {
3051 char *route_name = bprintf("%s#%s",
3052 (*(routing_component_t *)
3054 (path_src, max)))->name,
3055 (*(routing_component_t *)
3057 (path_dst, max)))->name);
3058 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
3059 xbt_free(route_name);
3065 xbt_dynar_free(&path_src);
3066 xbt_dynar_free(&path_dst);
3068 route_extended_t new_e_route = NULL;
3070 if (e_route_bypass) {
3072 unsigned int cpt = 0;
3073 new_e_route = xbt_new0(s_route_extended_t, 1);
3074 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
3075 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
3076 new_e_route->generic_route.link_list =
3077 xbt_dynar_new(global_routing->size_of_link, NULL);
3078 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
3079 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
3086 /* ************************************************************************** */
3087 /* ************************* GENERIC AUX FUNCTIONS ************************** */
3090 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
3091 void *data, int order)
3097 xbt_dynar_t links = NULL, links_id = NULL;
3099 new_route = xbt_new0(s_route_t, 1);
3100 new_route->link_list =
3101 xbt_dynar_new(global_routing->size_of_link, NULL);
3103 xbt_assert0(hierarchy == SURF_ROUTING_BASE,
3104 "the hierarchy type is not SURF_ROUTING_BASE");
3106 links = ((route_t) data)->link_list;
3109 links_id = new_route->link_list;
3111 xbt_dynar_foreach(links, cpt, link_name) {
3114 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3117 xbt_dynar_push(links_id, &link);
3119 xbt_dynar_unshift(links_id, &link);
3121 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3127 static route_extended_t
3128 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
3129 void *data, int order)
3133 route_extended_t e_route, new_e_route;
3136 xbt_dynar_t links = NULL, links_id = NULL;
3138 new_e_route = xbt_new0(s_route_extended_t, 1);
3139 new_e_route->generic_route.link_list =
3140 xbt_dynar_new(global_routing->size_of_link, NULL);
3141 new_e_route->src_gateway = NULL;
3142 new_e_route->dst_gateway = NULL;
3144 xbt_assert0(hierarchy == SURF_ROUTING_BASE
3145 || hierarchy == SURF_ROUTING_RECURSIVE,
3146 "the hierarchy type is not defined");
3148 if (hierarchy == SURF_ROUTING_BASE) {
3150 route = (route_t) data;
3151 links = route->link_list;
3153 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
3155 e_route = (route_extended_t) data;
3156 xbt_assert0(e_route->src_gateway
3157 && e_route->dst_gateway, "bad gateway, is null");
3158 links = e_route->generic_route.link_list;
3160 /* remeber not erase the gateway names */
3161 new_e_route->src_gateway = e_route->src_gateway;
3162 new_e_route->dst_gateway = e_route->dst_gateway;
3165 links_id = new_e_route->generic_route.link_list;
3167 xbt_dynar_foreach(links, cpt, link_name) {
3170 xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3173 xbt_dynar_push(links_id, &link);
3175 xbt_dynar_unshift(links_id, &link);
3177 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3183 static void generic_free_route(route_t route)
3186 xbt_dynar_free(&(route->link_list));
3191 static void generic_free_extended_route(route_extended_t e_route)
3194 xbt_dynar_free(&(e_route->generic_route.link_list));
3195 if (e_route->src_gateway)
3196 xbt_free(e_route->src_gateway);
3197 if (e_route->dst_gateway)
3198 xbt_free(e_route->dst_gateway);
3203 static routing_component_t generic_as_exist(routing_component_t find_from,
3204 routing_component_t to_find)
3206 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3207 xbt_dict_cursor_t cursor = NULL;
3210 routing_component_t elem;
3211 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
3212 if (to_find == elem || generic_as_exist(elem, to_find)) {
3222 static routing_component_t
3223 generic_autonomous_system_exist(routing_component_t rc, char *element)
3225 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3226 routing_component_t element_as, result, elem;
3227 xbt_dict_cursor_t cursor = NULL;
3229 element_as = ((network_element_info_t)
3230 xbt_dict_get_or_null
3231 (global_routing->where_network_elements,
3232 element))->rc_component;
3233 result = ((routing_component_t) - 1);
3234 if (element_as != rc)
3235 result = generic_as_exist(rc, element_as);
3239 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
3240 found = !strcmp(elem->name, element);
3250 static routing_component_t
3251 generic_processing_units_exist(routing_component_t rc, char *element)
3253 routing_component_t element_as;
3254 element_as = ((network_element_info_t)
3255 xbt_dict_get_or_null
3256 (global_routing->where_network_elements,
3257 element))->rc_component;
3258 if (element_as == rc)
3260 return generic_as_exist(rc, element_as);
3263 static void generic_src_dst_check(routing_component_t rc, const char *src,
3267 routing_component_t src_as = ((network_element_info_t)
3268 xbt_dict_get_or_null
3269 (global_routing->where_network_elements,
3270 src))->rc_component;
3271 routing_component_t dst_as = ((network_element_info_t)
3272 xbt_dict_get_or_null
3273 (global_routing->where_network_elements,
3274 dst))->rc_component;
3276 xbt_assert3(src_as != NULL && dst_as != NULL,
3277 "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
3278 src, dst, rc->name);
3279 xbt_assert4(src_as == dst_as,
3280 "The src(%s in %s) and dst(%s in %s) are in differents AS",
3281 src, src_as->name, dst, dst_as->name);
3282 xbt_assert2(rc == dst_as,
3283 "The routing component of src and dst is not the same as the network elements belong (%s==%s)",
3284 rc->name, dst_as->name);
3288 static void routing_parse_Sconfig(void)
3290 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
3293 static void routing_parse_Econfig(void)
3295 xbt_dict_cursor_t cursor = NULL;
3299 xbt_dict_foreach(current_property_set, cursor, key, elem) {
3300 cfg = bprintf("%s:%s",key,elem);
3301 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
3302 xbt_cfg_set_parse(_surf_cfg_set, cfg);
3304 XBT_INFO("The custom configuration '%s' is already define by user!",key);
3306 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
3309 static void routing_parse_Scluster(void)
3311 static int AX_ptr = 0;
3313 char *cluster_id = A_surfxml_cluster_id;
3314 char *cluster_prefix = A_surfxml_cluster_prefix;
3315 char *cluster_suffix = A_surfxml_cluster_suffix;
3316 char *cluster_radical = A_surfxml_cluster_radical;
3317 char *cluster_power = A_surfxml_cluster_power;
3318 char *cluster_core = A_surfxml_cluster_core;
3319 char *cluster_bw = A_surfxml_cluster_bw;
3320 char *cluster_lat = A_surfxml_cluster_lat;
3321 char *temp_cluster_bw = NULL;
3322 char *temp_cluster_lat = NULL;
3323 char *temp_cluster_power = NULL;
3324 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
3325 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
3326 char *cluster_availability_file = A_surfxml_cluster_availability_file;
3327 char *cluster_state_file = A_surfxml_cluster_state_file;
3328 char *host_id, *groups, *link_id = NULL;
3329 char *router_id, *link_router, *link_backbone;
3330 char *availability_file = bprintf("%s",cluster_availability_file);
3331 char *state_file = bprintf("%s",cluster_state_file);
3333 if(xbt_dict_size(patterns)==0)
3334 patterns = xbt_dict_new();
3336 xbt_dict_set(patterns,"id",cluster_id,NULL);
3337 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
3338 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
3340 #ifdef HAVE_PCRE_LIB
3341 char *route_src_dst;
3345 xbt_dynar_t radical_elements;
3346 xbt_dynar_t radical_ends;
3347 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
3348 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
3350 #ifndef HAVE_PCRE_LIB
3351 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3352 char *route_src, *route_dst;
3356 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3357 static unsigned int surfxml_buffer_stack_stack[1024];
3359 surfxml_buffer_stack_stack[0] = 0;
3361 surfxml_bufferstack_push(1);
3363 SURFXML_BUFFER_SET(AS_id, cluster_id);
3364 #ifdef HAVE_PCRE_LIB
3365 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3366 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
3368 SURFXML_BUFFER_SET(AS_routing, "Full");
3369 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
3371 SURFXML_START_TAG(AS);
3373 radical_elements = xbt_str_split(cluster_radical, ",");
3374 xbt_dynar_foreach(radical_elements, iter, groups) {
3375 radical_ends = xbt_str_split(groups, "-");
3376 switch (xbt_dynar_length(radical_ends)) {
3378 surf_parse_get_int(&start,
3379 xbt_dynar_get_as(radical_ends, 0, char *));
3380 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
3381 #ifndef HAVE_PCRE_LIB
3382 xbt_dynar_push_as(tab_elements_num, int, start);
3384 link_id = bprintf("%s_link_%d", cluster_id, start);
3386 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
3387 temp_cluster_power = bprintf("%s",cluster_power);
3388 temp_cluster_power = replace_random_parameter(temp_cluster_power);
3389 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
3390 A_surfxml_host_state = A_surfxml_host_state_ON;
3391 SURFXML_BUFFER_SET(host_id, host_id);
3392 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
3393 SURFXML_BUFFER_SET(host_core, cluster_core);
3394 SURFXML_BUFFER_SET(host_availability, "1.0");
3395 SURFXML_BUFFER_SET(host_coordinates, "");
3396 xbt_free(availability_file);
3397 availability_file = bprintf("%s",cluster_availability_file);
3398 xbt_free(state_file);
3399 state_file = bprintf("%s",cluster_state_file);
3400 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
3401 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
3402 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
3403 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
3404 XBT_DEBUG("</host>");
3405 SURFXML_START_TAG(host);
3406 SURFXML_END_TAG(host);
3409 temp_cluster_bw = bprintf("%s",cluster_bw);
3410 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
3411 temp_cluster_lat = bprintf("%s",cluster_lat);
3412 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
3413 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
3414 A_surfxml_link_state = A_surfxml_link_state_ON;
3415 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3416 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3417 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3418 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3419 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3420 SURFXML_BUFFER_SET(link_id, link_id);
3421 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
3422 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
3423 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3424 SURFXML_BUFFER_SET(link_latency_file, "");
3425 SURFXML_BUFFER_SET(link_state_file, "");
3426 SURFXML_START_TAG(link);
3427 SURFXML_END_TAG(link);
3429 xbt_free(temp_cluster_bw);
3430 xbt_free(temp_cluster_lat);
3437 surf_parse_get_int(&start,
3438 xbt_dynar_get_as(radical_ends, 0, char *));
3439 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3440 for (i = start; i <= end; i++) {
3441 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
3442 #ifndef HAVE_PCRE_LIB
3443 xbt_dynar_push_as(tab_elements_num, int, i);
3445 link_id = bprintf("%s_link_%d", cluster_id, i);
3447 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
3448 temp_cluster_power = bprintf("%s",cluster_power);
3449 temp_cluster_power = replace_random_parameter(temp_cluster_power);
3450 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
3451 A_surfxml_host_state = A_surfxml_host_state_ON;
3452 SURFXML_BUFFER_SET(host_id, host_id);
3453 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
3454 SURFXML_BUFFER_SET(host_core, cluster_core);
3455 SURFXML_BUFFER_SET(host_availability, "1.0");
3456 SURFXML_BUFFER_SET(host_coordinates, "");
3457 xbt_free(availability_file);
3458 availability_file = bprintf("%s",cluster_availability_file);
3459 xbt_free(state_file);
3460 state_file = bprintf("%s",cluster_state_file);
3461 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
3462 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
3463 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
3464 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
3465 XBT_DEBUG("</host>");
3466 SURFXML_START_TAG(host);
3467 SURFXML_END_TAG(host);
3469 xbt_free(temp_cluster_power);
3471 temp_cluster_bw = bprintf("%s",cluster_bw);
3472 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
3473 temp_cluster_lat = bprintf("%s",cluster_lat);
3474 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
3475 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
3476 A_surfxml_link_state = A_surfxml_link_state_ON;
3477 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3478 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3479 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3480 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3481 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3482 SURFXML_BUFFER_SET(link_id, link_id);
3483 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
3484 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
3485 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3486 SURFXML_BUFFER_SET(link_latency_file, "");
3487 SURFXML_BUFFER_SET(link_state_file, "");
3488 SURFXML_START_TAG(link);
3489 SURFXML_END_TAG(link);
3491 xbt_free(temp_cluster_bw);
3492 xbt_free(temp_cluster_lat);
3499 XBT_DEBUG("Malformed radical");
3502 xbt_dynar_free(&radical_ends);
3504 xbt_dynar_free(&radical_elements);
3508 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
3510 link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
3511 link_backbone = bprintf("%s_backbone", cluster_id);
3513 XBT_DEBUG("<router id=\"%s\"/>", router_id);
3514 SURFXML_BUFFER_SET(router_id, router_id);
3515 SURFXML_START_TAG(router);
3516 SURFXML_END_TAG(router);
3519 xbt_dict_set(patterns, "radical", bprintf("_router"), xbt_free);
3520 temp_cluster_bw = bprintf("%s",cluster_bw);
3521 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
3522 temp_cluster_lat = bprintf("%s",cluster_lat);
3523 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
3524 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,temp_cluster_bw, temp_cluster_lat);
3525 A_surfxml_link_state = A_surfxml_link_state_ON;
3526 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3527 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3528 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3529 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3530 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3531 SURFXML_BUFFER_SET(link_id, link_router);
3532 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
3533 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
3534 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3535 SURFXML_BUFFER_SET(link_latency_file, "");
3536 SURFXML_BUFFER_SET(link_state_file, "");
3537 SURFXML_START_TAG(link);
3538 SURFXML_END_TAG(link);
3540 xbt_free(temp_cluster_bw);
3541 xbt_free(temp_cluster_lat);
3543 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
3544 A_surfxml_link_state = A_surfxml_link_state_ON;
3545 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3546 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
3547 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3548 SURFXML_BUFFER_SET(link_id, link_backbone);
3549 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
3550 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
3551 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3552 SURFXML_BUFFER_SET(link_latency_file, "");
3553 SURFXML_BUFFER_SET(link_state_file, "");
3554 SURFXML_START_TAG(link);
3555 SURFXML_END_TAG(link);
3559 #ifdef HAVE_PCRE_LIB
3560 char *new_suffix = xbt_strdup("");
3562 radical_elements = xbt_str_split(cluster_suffix, ".");
3563 xbt_dynar_foreach(radical_elements, iter, groups) {
3564 if (strcmp(groups, "")) {
3565 char *old_suffix = new_suffix;
3566 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
3570 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
3571 xbt_dynar_free(&radical_elements);
3574 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
3575 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
3576 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
3578 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
3579 XBT_DEBUG("symmetrical=\"NO\">");
3580 SURFXML_BUFFER_SET(route_src, route_src_dst);
3581 SURFXML_BUFFER_SET(route_dst, route_src_dst);
3582 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3583 SURFXML_START_TAG(route);
3585 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
3586 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
3587 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3588 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3589 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3590 SURFXML_START_TAG(link_ctn);
3591 SURFXML_END_TAG(link_ctn);
3593 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
3594 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
3595 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3596 SURFXML_START_TAG(link_ctn);
3597 SURFXML_END_TAG(link_ctn);
3599 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
3600 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
3601 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3602 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3603 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3604 SURFXML_START_TAG(link_ctn);
3605 SURFXML_END_TAG(link_ctn);
3607 XBT_DEBUG("</route>");
3608 SURFXML_END_TAG(route);
3610 free(pcre_link_dst);
3611 free(pcre_link_backbone);
3612 free(pcre_link_src);
3613 free(route_src_dst);
3615 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
3616 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
3617 if (i == xbt_dynar_length(tab_elements_num)) {
3618 route_src = router_id;
3621 bprintf("%s%d%s", cluster_prefix,
3622 xbt_dynar_get_as(tab_elements_num, i, int),
3626 if (j == xbt_dynar_length(tab_elements_num)) {
3627 route_dst = router_id;
3630 bprintf("%s%d%s", cluster_prefix,
3631 xbt_dynar_get_as(tab_elements_num, j, int),
3635 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
3636 XBT_DEBUG("symmetrical=\"NO\">");
3637 SURFXML_BUFFER_SET(route_src, route_src);
3638 SURFXML_BUFFER_SET(route_dst, route_dst);
3639 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3640 SURFXML_START_TAG(route);
3642 if (i == xbt_dynar_length(tab_elements_num)) {
3643 route_src = link_router;
3646 bprintf("%s_link_%d", cluster_id,
3647 xbt_dynar_get_as(tab_elements_num, i, int));
3650 if (j == xbt_dynar_length(tab_elements_num)) {
3651 route_dst = link_router;
3654 bprintf("%s_link_%d", cluster_id,
3655 xbt_dynar_get_as(tab_elements_num, j, int));
3658 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_src);
3659 SURFXML_BUFFER_SET(link_ctn_id, route_src);
3660 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3661 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3662 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3663 SURFXML_START_TAG(link_ctn);
3664 SURFXML_END_TAG(link_ctn);
3666 XBT_DEBUG("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3667 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3668 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3669 SURFXML_START_TAG(link_ctn);
3670 SURFXML_END_TAG(link_ctn);
3672 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_dst);
3673 SURFXML_BUFFER_SET(link_ctn_id, route_dst);
3674 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3675 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3676 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3677 SURFXML_START_TAG(link_ctn);
3678 SURFXML_END_TAG(link_ctn);
3680 XBT_DEBUG("</route>");
3681 SURFXML_END_TAG(route);
3684 xbt_dynar_free(&tab_elements_num);
3689 free(link_backbone);
3691 xbt_dict_free(&patterns);
3692 free(availability_file);
3696 SURFXML_END_TAG(AS);
3699 surfxml_bufferstack_pop(1);
3702 * This function take a string and replace parameters from patterns dict.
3703 * It returns the new value.
3705 static char* replace_random_parameter(char * string)
3707 char *test_string = NULL;
3709 if(xbt_dict_size(random_value)==0)
3712 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
3713 test_string = bprintf("${%s}", string);
3714 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
3716 if (strcmp(test_string,"")) { //if not empty, keep this value.
3718 string = test_string;
3719 } //In other case take old value (without ${})
3724 static void routing_parse_Speer(void)
3726 static int AX_ptr = 0;
3728 char *peer_id = A_surfxml_peer_id;
3729 char *peer_power = A_surfxml_peer_power;
3730 char *peer_bw_in = A_surfxml_peer_bw_in;
3731 char *peer_bw_out = A_surfxml_peer_bw_out;
3732 char *peer_lat = A_surfxml_peer_lat;
3733 char *peer_coord = A_surfxml_peer_coordinates;
3734 char *peer_state_file = A_surfxml_peer_state_file;
3735 char *peer_availability_file = A_surfxml_peer_availability_file;
3737 char *host_id = NULL;
3738 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
3740 #ifdef HAVE_PCRE_LIB
3744 int peer_sharing_policy = AX_surfxml_peer_sharing_policy;
3746 #ifndef HAVE_PCRE_LIB
3747 //xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3748 //char *route_src, *route_dst;
3752 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3753 static unsigned int surfxml_buffer_stack_stack[1024];
3755 surfxml_buffer_stack_stack[0] = 0;
3757 surfxml_bufferstack_push(1);
3759 SURFXML_BUFFER_SET(AS_id, peer_id);
3760 SURFXML_BUFFER_SET(AS_coordinates, peer_coord);
3761 #ifdef HAVE_PCRE_LIB
3762 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3763 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", peer_id);
3765 SURFXML_BUFFER_SET(AS_routing, "Full");
3766 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
3768 SURFXML_START_TAG(AS);
3771 host_id = bprintf("peer_%s", peer_id);
3772 router_id = bprintf("router_%s", peer_id);
3773 link_id_up = bprintf("link_%s_up", peer_id);
3774 link_id_down = bprintf("link_%s_down", peer_id);
3776 link_router = bprintf("%s_link_router", peer_id);
3777 link_backbone = bprintf("%s_backbone", peer_id);
3779 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
3780 A_surfxml_host_state = A_surfxml_host_state_ON;
3781 SURFXML_BUFFER_SET(host_id, host_id);
3782 SURFXML_BUFFER_SET(host_power, peer_power);
3783 SURFXML_BUFFER_SET(host_availability, "1.0");
3784 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
3785 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
3786 SURFXML_BUFFER_SET(host_coordinates, "");
3787 SURFXML_START_TAG(host);
3788 SURFXML_END_TAG(host);
3790 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
3791 SURFXML_BUFFER_SET(router_id, router_id);
3792 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
3793 SURFXML_START_TAG(router);
3794 SURFXML_END_TAG(router);
3796 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
3797 A_surfxml_link_state = A_surfxml_link_state_ON;
3798 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3799 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3800 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3801 SURFXML_BUFFER_SET(link_id, link_id_up);
3802 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
3803 SURFXML_BUFFER_SET(link_latency, peer_lat);
3804 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3805 SURFXML_BUFFER_SET(link_latency_file, "");
3806 SURFXML_BUFFER_SET(link_state_file, "");
3807 SURFXML_START_TAG(link);
3808 SURFXML_END_TAG(link);
3810 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
3811 A_surfxml_link_state = A_surfxml_link_state_ON;
3812 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3813 if(peer_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3814 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3815 SURFXML_BUFFER_SET(link_id, link_id_down);
3816 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
3817 SURFXML_BUFFER_SET(link_latency, peer_lat);
3818 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3819 SURFXML_BUFFER_SET(link_latency_file, "");
3820 SURFXML_BUFFER_SET(link_state_file, "");
3821 SURFXML_START_TAG(link);
3822 SURFXML_END_TAG(link);
3827 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", peer_id, router_id);
3828 XBT_DEBUG("symmetrical=\"NO\">");
3829 SURFXML_BUFFER_SET(route_src, peer_id);
3830 SURFXML_BUFFER_SET(route_dst, router_id);
3831 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3832 SURFXML_START_TAG(route);
3834 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
3835 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
3836 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3837 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3838 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3839 SURFXML_START_TAG(link_ctn);
3840 SURFXML_END_TAG(link_ctn);
3842 XBT_DEBUG("</route>");
3843 SURFXML_END_TAG(route);
3846 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, peer_id);
3847 XBT_DEBUG("symmetrical=\"NO\">");
3848 SURFXML_BUFFER_SET(route_src, router_id);
3849 SURFXML_BUFFER_SET(route_dst, peer_id);
3850 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3851 SURFXML_START_TAG(route);
3853 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
3854 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
3855 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3856 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3857 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3858 SURFXML_START_TAG(link_ctn);
3859 SURFXML_END_TAG(link_ctn);
3861 XBT_DEBUG("</route>");
3862 SURFXML_END_TAG(route);
3865 SURFXML_END_TAG(AS);
3868 //xbt_dynar_free(&tab_elements_num);
3870 surfxml_bufferstack_pop(1);
3873 static void routing_parse_Srandom(void)
3875 double mean, std, min, max, seed;
3876 char *random_id = A_surfxml_random_id;
3877 char *random_radical = A_surfxml_random_radical;
3878 surf_parse_get_double(&mean,A_surfxml_random_mean);
3879 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
3880 surf_parse_get_double(&min,A_surfxml_random_min);
3881 surf_parse_get_double(&max,A_surfxml_random_max);
3882 surf_parse_get_double(&seed,A_surfxml_random_seed);
3886 random_data_t random = xbt_new0(s_random_data_t, 1);
3889 xbt_dynar_t radical_elements;
3893 xbt_dynar_t radical_ends;
3895 random->generator = A_surfxml_random_generator;
3896 random->seed = seed;
3900 /* Check user stupidities */
3902 THROW2(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
3904 THROW2(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
3907 THROW2(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
3910 /* normalize the mean and standard deviation before storing */
3911 random->mean = (mean - min) / (max - min);
3912 random->std = std / (max - min);
3914 if (random->mean * (1 - random->mean) < random->std * random->std)
3915 THROW2(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
3916 random->mean, random->std);
3918 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
3928 if(xbt_dict_size(random_value)==0)
3929 random_value = xbt_dict_new();
3931 if(!strcmp(random_radical,""))
3933 res = random_generate(random);
3934 xbt_dict_set(random_value, random_id, bprintf("%f",res), free);
3938 radical_elements = xbt_str_split(random_radical, ",");
3939 xbt_dynar_foreach(radical_elements, iter, groups) {
3940 radical_ends = xbt_str_split(groups, "-");
3941 switch (xbt_dynar_length(radical_ends)) {
3943 xbt_assert1(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
3944 res = random_generate(random);
3945 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
3946 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
3950 case 2: surf_parse_get_int(&start,
3951 xbt_dynar_get_as(radical_ends, 0, char *));
3952 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3953 for (i = start; i <= end; i++) {
3954 xbt_assert1(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
3955 res = random_generate(random);
3956 tmpbuf = bprintf("%s%d",random_id,i);
3957 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
3962 XBT_INFO("Malformed radical");
3964 res = random_generate(random);
3965 xbt_dict_set(random_value, bprintf("%s_router",random_id), bprintf("%f",res), free);
3967 xbt_dynar_free(&radical_ends);
3969 xbt_dynar_free(&radical_elements);
3973 static void routing_parse_Erandom(void)
3975 xbt_dict_cursor_t cursor = NULL;
3979 xbt_dict_foreach(random_value, cursor, key, elem) {
3980 XBT_DEBUG("%s = %s",key,elem);
3987 * New methods to init the routing model component from the lua script
3991 * calling parse_S_AS_lua with lua values
3993 void routing_AS_init(const char *AS_id, const char *AS_routing)
3995 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
3999 * calling parse_E_AS_lua to fisnish the creation of routing component
4001 void routing_AS_end(const char *AS_id)
4003 parse_E_AS_lua((char *) AS_id);
4007 * add a host to the network element list
4010 void routing_add_host(const char *host_id)
4012 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
4016 * Set a new link on the actual list of link for a route or ASroute
4018 void routing_add_link(const char *link_id)
4020 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
4024 *Set the endpoints for a route
4026 void routing_set_route(const char *src_id, const char *dst_id)
4028 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
4032 * Store the route by calling parse_E_route_store_route
4034 void routing_store_route(void)
4036 parse_E_route_store_route();