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);
77 static void clean_dict_random(void);
79 /* this lines are only for replace use like index in the model table */
84 SURF_MODEL_DIJKSTRACACHE,
92 /* must be finish with null and carefull if change de order */
93 struct s_model_type routing_models[] = { {"Full",
94 "Full routing data (fast, large memory requirements, fully expressive)",
100 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
101 model_floyd_create, model_floyd_load, model_floyd_unload,
104 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
105 model_dijkstra_create, model_dijkstra_both_load,
106 model_dijkstra_both_unload, model_dijkstra_both_end},
108 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
109 model_dijkstracache_create, model_dijkstra_both_load,
110 model_dijkstra_both_unload, model_dijkstra_both_end},
111 {"none", "No routing (usable with Constant network only)",
112 model_none_create, model_none_load, model_none_unload, model_none_end},
114 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
115 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
116 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
117 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
119 {NULL, NULL, NULL, NULL, NULL, NULL}
122 /* ************************************************************************** */
123 /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
125 static void generic_set_processing_unit(routing_component_t rc,
127 static void generic_set_autonomous_system(routing_component_t rc,
129 static void generic_set_bypassroute(routing_component_t rc,
130 const char *src, const char *dst,
131 route_extended_t e_route);
133 static int surf_link_resource_cmp(const void *a, const void *b);
134 static int surf_pointer_resource_cmp(const void *a, const void *b);
136 /* ************************************************************************** */
137 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
139 static double generic_get_link_latency(routing_component_t rc, const char *src, const char *dst);
140 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc);
141 static route_extended_t generic_get_bypassroute(routing_component_t rc,
145 /* ************************************************************************** */
146 /* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */
148 static route_extended_t
149 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
150 void *data, int order);
152 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
153 void *data, int order);
154 static void generic_free_route(route_t route);
155 static void generic_free_extended_route(route_extended_t e_route);
156 static routing_component_t
157 generic_autonomous_system_exist(routing_component_t rc, char *element);
158 static routing_component_t
159 generic_processing_units_exist(routing_component_t rc, char *element);
160 static void generic_src_dst_check(routing_component_t rc, const char *src,
163 /* ************************************************************************** */
164 /* **************************** GLOBAL FUNCTIONS **************************** */
166 /* global parse functions */
167 static const char *src = NULL; /* temporary store the source name of a route */
168 static const char *dst = NULL; /* temporary store the destination name of a route */
169 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
170 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
171 static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
174 static double eculidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
176 double src_coord, dst_coord;
178 src_coord = atof(xbt_dynar_get_as(src, index, char *));
179 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
181 return (src_coord-dst_coord)*(src_coord-dst_coord);
185 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst)
187 double euclidean_dist;
188 xbt_dynar_t src_ctn, dst_ctn;
189 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
190 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
191 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
192 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
194 if(dst_ctn == NULL || src_ctn == NULL)
195 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
197 euclidean_dist = sqrt (eculidean_dist_comp(0,src_ctn,dst_ctn)+eculidean_dist_comp(1,src_ctn,dst_ctn))
198 +fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
200 xbt_assert2(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
202 return euclidean_dist;
205 x = atof(xbt_dynar_get_as(src_ctn, 0, char *))-atof(xbt_dynar_get_as(dst_ctn, 0, char *));
206 y = atof(xbt_dynar_get_as(src_ctn, 1, char *));
207 h = atof(xbt_dynar_get_as(ctn, 2, char *));
208 sqrt((c1->x - c2->x) * (c1->x - c2->x) + (c1->y - c2->y) * (c1->y - c2->y)) + fabs(c1->h) + fabs(c2->h);
210 if (strcmp(coord,"")) {
211 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
212 xbt_dynar_shrink(ctn,0);
213 xbt_lib_set(host_lib, host_id, COORD_HOST_LEVEL, ctn);
219 * \brief Add a "host" to the network element list
221 static void parse_S_host(const char *host_id, const char* coord)
223 network_element_info_t info = NULL;
224 if (current_routing->hierarchy == SURF_ROUTING_NULL)
225 current_routing->hierarchy = SURF_ROUTING_BASE;
226 xbt_assert1(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
227 "Reading a host, processing unit \"%s\" already exists",
229 xbt_assert1(current_routing->set_processing_unit,
230 "no defined method \"set_processing_unit\" in \"%s\"",
231 current_routing->name);
232 (*(current_routing->set_processing_unit)) (current_routing, host_id);
233 info = xbt_new0(s_network_element_info_t, 1);
234 info->rc_component = current_routing;
235 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
236 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
237 if (strcmp(coord,"")) {
238 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
239 xbt_dynar_shrink(ctn, 0);
240 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
244 static void parse_E_host(void)
246 xbt_dict_cursor_t cursor = NULL;
250 xbt_dict_foreach(current_property_set, cursor, key, elem) {
251 XBT_DEBUG("property : %s = %s",key,elem);
256 * \brief Add a host to the network element list from XML
258 static void parse_S_host_XML(void)
260 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
262 static void parse_E_host_XML(void)
268 * \brief Add a host to the network element list from lua script
270 static void parse_S_host_lua(const char *host_id, const char *coord)
272 parse_S_host(host_id, coord);
277 * \brief Add a "router" to the network element list
279 static void parse_S_router(const char *router_id)
281 network_element_info_t info = NULL;
283 if (current_routing->hierarchy == SURF_ROUTING_NULL)
284 current_routing->hierarchy = SURF_ROUTING_BASE;
285 xbt_assert1(!xbt_lib_get_or_null(as_router_lib,A_surfxml_router_id, ROUTING_ASR_LEVEL),
286 "Reading a router, processing unit \"%s\" already exists",
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,
293 info = xbt_new0(s_network_element_info_t, 1);
294 info->rc_component = current_routing;
295 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
297 xbt_lib_set(as_router_lib,router_id,ROUTING_ASR_LEVEL,(void *) info);
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_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn);
306 * brief Add a "router" to the network element list from XML description
308 static void parse_S_router_XML(void)
310 return parse_S_router(A_surfxml_router_id);
314 * brief Add a "router" to the network element list from XML description
316 static void parse_S_router_lua(const char* router_id)
318 return parse_S_router(router_id);
322 * \brief Set the endponints for a route
324 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
326 if (src != NULL && dst != NULL && link_list != NULL)
327 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
331 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0,
332 "Some limits are null in the route between \"%s\" and \"%s\"",
334 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
338 * \brief Set the endpoints for a route from XML
340 static void parse_S_route_new_and_endpoints_XML(void)
342 parse_S_route_new_and_endpoints(A_surfxml_route_src,
343 A_surfxml_route_dst);
347 * \brief Set the endpoints for a route from lua
349 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
351 parse_S_route_new_and_endpoints(id_src, id_dst);
355 * \brief Set the endponints and gateways for a ASroute
357 static void parse_S_ASroute_new_and_endpoints(void)
359 if (src != NULL && dst != NULL && link_list != NULL)
360 THROW2(arg_error, 0, "Route between %s to %s can not be defined",
361 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
362 src = A_surfxml_ASroute_src;
363 dst = A_surfxml_ASroute_dst;
364 gw_src = A_surfxml_ASroute_gw_src;
365 gw_dst = A_surfxml_ASroute_gw_dst;
366 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
367 || strlen(gw_dst) > 0,
368 "Some limits are null in the route between \"%s\" and \"%s\"",
370 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
374 * \brief Set the endponints for a bypassRoute
376 static void parse_S_bypassRoute_new_and_endpoints(void)
378 if (src != NULL && dst != NULL && link_list != NULL)
380 "Bypass Route between %s to %s can not be defined",
381 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
382 src = A_surfxml_bypassRoute_src;
383 dst = A_surfxml_bypassRoute_dst;
384 gw_src = A_surfxml_bypassRoute_gw_src;
385 gw_dst = A_surfxml_bypassRoute_gw_dst;
386 xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
387 || strlen(gw_dst) > 0,
388 "Some limits are null in the route between \"%s\" and \"%s\"",
390 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
394 * \brief Set a new link on the actual list of link for a route or ASroute
396 static void parse_E_link_ctn_new_elem(const char *link_id)
399 val = xbt_strdup(link_id);
400 xbt_dynar_push(link_list, &val);
404 * \brief Set a new link on the actual list of link for a route or ASroute from XML
407 static void parse_E_link_ctn_new_elem_XML(void)
409 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
410 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
411 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
412 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
413 parse_E_link_ctn_new_elem(link_id);
416 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
417 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
418 parse_E_link_ctn_new_elem(link_id);
424 * \brief Set a new link on the actual list of link for a route or ASroute from lua
426 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
428 parse_E_link_ctn_new_elem(link_id);
432 * \brief Store the route by calling the set_route function of the current routing component
434 static void parse_E_route_store_route(void)
436 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
437 route->generic_route.link_list = link_list;
438 xbt_assert1(current_routing->set_route,
439 "no defined method \"set_route\" in \"%s\"",
440 current_routing->name);
441 (*(current_routing->set_route)) (current_routing, src, dst, route);
448 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
450 static void parse_E_ASroute_store_route(void)
452 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
453 e_route->generic_route.link_list = link_list;
454 e_route->src_gateway = xbt_strdup(gw_src);
455 e_route->dst_gateway = xbt_strdup(gw_dst);
456 xbt_assert1(current_routing->set_ASroute,
457 "no defined method \"set_ASroute\" in \"%s\"",
458 current_routing->name);
459 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
468 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
470 static void parse_E_bypassRoute_store_route(void)
472 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
473 e_route->generic_route.link_list = link_list;
474 e_route->src_gateway = xbt_strdup(gw_src);
475 e_route->dst_gateway = xbt_strdup(gw_dst);
476 xbt_assert1(current_routing->set_bypassroute,
477 "no defined method \"set_bypassroute\" in \"%s\"",
478 current_routing->name);
479 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
489 * \brief Make a new routing component
491 * make the new structure and
492 * set the parsing functions to allows parsing the part of the routing tree
494 static void parse_S_AS(char *AS_id, char *AS_routing)
496 routing_component_t new_routing;
497 model_type_t model = NULL;
498 char *wanted = AS_routing;
500 /* seach the routing model */
501 for (cpt = 0; routing_models[cpt].name; cpt++)
502 if (!strcmp(wanted, routing_models[cpt].name))
503 model = &routing_models[cpt];
504 /* if its not exist, error */
506 fprintf(stderr, "Routing model %s not found. Existing models:\n",
508 for (cpt = 0; routing_models[cpt].name; cpt++)
509 if (!strcmp(wanted, routing_models[cpt].name))
510 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
511 routing_models[cpt].desc);
515 /* make a new routing component */
516 new_routing = (routing_component_t) (*(model->create)) ();
517 new_routing->routing = model;
518 new_routing->hierarchy = SURF_ROUTING_NULL;
519 new_routing->name = xbt_strdup(AS_id);
520 new_routing->routing_sons = xbt_dict_new();
522 /* Hack for Vivaldi */
523 if(!strcmp(model->name,"Vivaldi"))
524 new_routing->get_latency = vivaldi_get_link_latency;
526 if (current_routing == NULL && global_routing->root == NULL) {
528 /* it is the first one */
529 new_routing->routing_father = NULL;
530 global_routing->root = new_routing;
532 } else if (current_routing != NULL && global_routing->root != NULL) {
534 xbt_assert1(!xbt_dict_get_or_null
535 (current_routing->routing_sons, AS_id),
536 "The AS \"%s\" already exists", AS_id);
537 /* it is a part of the tree */
538 new_routing->routing_father = current_routing;
539 /* set the father behavior */
540 if (current_routing->hierarchy == SURF_ROUTING_NULL)
541 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
542 /* add to the sons dictionary */
543 xbt_dict_set(current_routing->routing_sons, AS_id,
544 (void *) new_routing, NULL);
545 /* add to the father element list */
546 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
547 /* unload the prev parse rules */
548 (*(current_routing->routing->unload)) ();
551 THROW0(arg_error, 0, "All defined components must be belong to a AS");
553 /* set the new parse rules */
554 (*(new_routing->routing->load)) ();
555 /* set the new current component of the tree */
556 current_routing = new_routing;
560 * Detect the routing model type of the routing component from XML platforms
562 static void parse_S_AS_XML(void)
564 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
566 if (strcmp(A_surfxml_AS_coordinates,"")) {
567 XBT_DEBUG("%s coordinates : %s", A_surfxml_AS_id, A_surfxml_AS_coordinates);
568 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_AS_coordinates, " ");
569 xbt_dynar_shrink(ctn, 0);
570 xbt_lib_set(as_router_lib,A_surfxml_AS_id,COORD_ASR_LEVEL,(void *) ctn);
575 * define the routing model type of routing component from lua script
577 static void parse_S_AS_lua(char *id, char *mode)
579 parse_S_AS(id, mode);
584 * \brief Finish the creation of a new routing component
586 * When you finish to read the routing component, other structures must be created.
587 * the "end" method allow to do that for any routing model type
589 static void parse_E_AS(const char *AS_id)
592 if (current_routing == NULL) {
593 THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id);
595 network_element_info_t info = NULL;
596 xbt_assert1(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
597 "The AS \"%s\" already exists",current_routing->name);
598 info = xbt_new0(s_network_element_info_t, 1);
599 info->rc_component = current_routing->routing_father;
600 info->rc_type = SURF_NETWORK_ELEMENT_AS;
601 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
603 (*(current_routing->routing->unload)) ();
604 (*(current_routing->routing->end)) ();
605 current_routing = current_routing->routing_father;
606 if (current_routing != NULL)
607 (*(current_routing->routing->load)) ();
612 * \brief Finish the creation of a new routing component from XML
614 static void parse_E_AS_XML(void)
616 parse_E_AS(A_surfxml_AS_id);
620 * \brief Finish the creation of a new routing component from lua
622 static void parse_E_AS_lua(const char *id)
627 /* Aux Business methods */
630 * \brief Get the AS name of the element
632 * \param name the host name
635 static char* elements_As_name(const char *name)
637 routing_component_t as_comp;
639 /* (1) find the as where the host is located */
640 as_comp = ((network_element_info_t)
641 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
642 return as_comp->name;
647 * \brief Get the AS father and the first elements of the chain
649 * \param src the source host name
650 * \param dst the destination host name
652 * Get the common father of the to processing units, and the first different
653 * father in the chain
655 static xbt_dynar_t elements_father(const char *src, const char *dst)
658 xbt_assert0(src && dst, "bad parameters for \"elements_father\" method");
660 xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
662 routing_component_t src_as, dst_as;
663 int index_src, index_dst, index_father_src, index_father_dst;
664 xbt_dynar_t path_src = NULL;
665 xbt_dynar_t path_dst = NULL;
666 routing_component_t current = NULL;
667 routing_component_t *current_src = NULL;
668 routing_component_t *current_dst = NULL;
669 routing_component_t *father = NULL;
671 /* (1) find the as where the src and dst are located */
672 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
673 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
674 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
675 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
676 src_as = ((network_element_info_t)src_data)->rc_component;
677 dst_as = ((network_element_info_t)dst_data)->rc_component;
681 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
684 /* (2) find the path to the root routing component */
685 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
687 while (current != NULL) {
688 xbt_dynar_push(path_src, ¤t);
689 current = current->routing_father;
691 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
693 while (current != NULL) {
694 xbt_dynar_push(path_dst, ¤t);
695 current = current->routing_father;
698 /* (3) find the common father */
699 index_src = path_src->used - 1;
700 index_dst = path_dst->used - 1;
701 current_src = xbt_dynar_get_ptr(path_src, index_src);
702 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
703 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
704 current_src = xbt_dynar_get_ptr(path_src, index_src);
705 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
711 current_src = xbt_dynar_get_ptr(path_src, index_src);
712 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
714 /* (4) they are not in the same routing component, make the path */
715 index_father_src = index_src + 1;
716 index_father_dst = index_dst + 1;
718 if (*current_src == *current_dst)
719 father = current_src;
721 father = xbt_dynar_get_ptr(path_src, index_father_src);
723 /* (5) result generation */
724 xbt_dynar_push(result, father); /* first same the father of src and dst */
725 xbt_dynar_push(result, current_src); /* second the first different father of src */
726 xbt_dynar_push(result, current_dst); /* three the first different father of dst */
728 xbt_dynar_free(&path_src);
729 xbt_dynar_free(&path_dst);
734 /* Global Business methods */
737 * \brief Recursive function for get_route
739 * \param src the source host name
740 * \param dst the destination host name
742 * This fuction is call by "get_route". It allow to walk through the
743 * routing components tree.
745 static route_extended_t _get_route(const char *src, const char *dst)
749 unsigned int cpt = 0;
751 XBT_DEBUG("Solve route \"%s\" to \"%s\"", src, dst);
753 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
755 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
758 xbt_dynar_t elem_father_list = elements_father(src, dst);
760 routing_component_t common_father =
761 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
762 routing_component_t src_father =
763 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
764 routing_component_t dst_father =
765 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
767 e_route = xbt_new0(s_route_extended_t, 1);
768 e_route->src_gateway = NULL;
769 e_route->dst_gateway = NULL;
770 e_route->generic_route.link_list =
771 xbt_dynar_new(global_routing->size_of_link, NULL);
773 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
775 if (strcmp(src, dst)) {
777 (*(common_father->get_route)) (common_father, src, dst);
778 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
780 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
781 xbt_dynar_push(e_route->generic_route.link_list, &link);
783 generic_free_extended_route(e_route_cnt);
786 } else { /* SURF_ROUTING_RECURSIVE */
788 route_extended_t e_route_bypass = NULL;
790 if (common_father->get_bypass_route)
792 (*(common_father->get_bypass_route)) (common_father, src, dst);
795 e_route_cnt = e_route_bypass;
798 (*(common_father->get_route)) (common_father, src_father->name,
801 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
802 src_father->name, dst_father->name);
804 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
805 (e_route_cnt->dst_gateway == NULL),
806 "bad gateway for route between \"%s\" and \"%s\"", src,
809 if (strcmp(src, e_route_cnt->src_gateway)) {
810 e_route_src = _get_route(src, e_route_cnt->src_gateway);
811 xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
812 e_route_cnt->src_gateway);
813 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
814 xbt_dynar_push(e_route->generic_route.link_list, &link);
818 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
819 xbt_dynar_push(e_route->generic_route.link_list, &link);
822 if (strcmp(e_route_cnt->dst_gateway, dst)) {
823 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
824 xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
825 e_route_cnt->dst_gateway, dst);
826 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
827 xbt_dynar_push(e_route->generic_route.link_list, &link);
831 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
832 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
834 generic_free_extended_route(e_route_src);
835 generic_free_extended_route(e_route_cnt);
836 generic_free_extended_route(e_route_dst);
839 xbt_dynar_free(&elem_father_list);
844 static double _get_latency(const char *src, const char *dst)
846 double latency, latency_src, latency_dst = 0.0;
848 XBT_DEBUG("Solve route \"%s\" to \"%s\"", src, dst);
849 xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
851 route_extended_t e_route_cnt;
853 xbt_dynar_t elem_father_list = elements_father(src, dst);
855 routing_component_t common_father =
856 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
857 routing_component_t src_father =
858 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
859 routing_component_t dst_father =
860 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
862 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
864 if (strcmp(src, dst)) {
866 (*(common_father->get_latency)) (common_father, src, dst);
867 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"", src,
870 } else { /* SURF_ROUTING_RECURSIVE */
871 route_extended_t e_route_bypass = NULL;
872 if (common_father->get_bypass_route)
874 (*(common_father->get_bypass_route)) (common_father, src, dst);
876 xbt_assert0(!e_route_bypass,"Bypass cannot work yet with get_latency");
879 (*(common_father->get_route)) (common_father, src_father->name,
882 xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
883 src_father->name, dst_father->name);
885 xbt_assert2((e_route_cnt->src_gateway == NULL) ==
886 (e_route_cnt->dst_gateway == NULL),
887 "bad gateway for route between \"%s\" and \"%s\"", src,
890 (*(common_father->get_latency)) (common_father, elements_As_name(src),
891 elements_As_name(dst));
893 xbt_assert2(latency>=0, "no route between \"%s\" and \"%s\"",
894 src_father->name, dst_father->name);
897 if (src != e_route_cnt->src_gateway) {
899 latency_src = _get_latency(src, e_route_cnt->src_gateway);
900 xbt_assert2(latency_src>=0, "no route between \"%s\" and \"%s\"", src,
901 e_route_cnt->src_gateway);
902 latency += latency_src;
905 if (e_route_cnt->dst_gateway != dst) {
907 latency_dst = _get_latency(e_route_cnt->dst_gateway, dst);
908 xbt_assert2(latency_dst>=0, "no route between \"%s\" and \"%s\"",
909 e_route_cnt->dst_gateway, dst);
910 latency += latency_dst;
915 xbt_dynar_free(&elem_father_list);
921 * \brief Generic method: find a route between hosts
923 * \param src the source host name
924 * \param dst the destination host name
926 * walk through the routing components tree and find a route between hosts
927 * by calling the differents "get_route" functions in each routing component.
928 * No need to free the returned dynar. It will be freed at the next call.
930 static xbt_dynar_t get_route(const char *src, const char *dst)
933 route_extended_t e_route;
934 xbt_dynar_t elem_father_list = NULL;
935 routing_component_t common_father = NULL;
937 if (strcmp(src, dst))
938 e_route = _get_route(src, dst);
940 elem_father_list = elements_father(src, dst);
942 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
944 e_route = (*(common_father->get_route)) (common_father, src, dst);
945 xbt_dynar_free(&elem_father_list);
948 xbt_assert2(e_route, "no route between \"%s\" and \"%s\"", src, dst);
950 if (global_routing->last_route)
951 xbt_dynar_free(&(global_routing->last_route));
952 global_routing->last_route = e_route->generic_route.link_list;
954 if (e_route->src_gateway)
955 xbt_free(e_route->src_gateway);
956 if (e_route->dst_gateway)
957 xbt_free(e_route->dst_gateway);
962 if (xbt_dynar_length(global_routing->last_route) == 0)
966 return global_routing->last_route;
970 * \brief Generic method: find a route between hosts
972 * \param src the source host name
973 * \param dst the destination host name
975 * walk through the routing components tree and find a route between hosts
976 * by calling the differents "get_route" functions in each routing component.
977 * Leaves the caller the responsability to clean the returned dynar.
979 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
981 xbt_dynar_t d = get_route(src,dst);
982 global_routing->last_route = NULL;
987 static double get_latency(const char *src, const char *dst)
990 double latency = -1.0;
991 xbt_dynar_t elem_father_list = elements_father(src, dst);
992 routing_component_t common_father =
993 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
995 if (strcmp(src, dst))
996 latency = _get_latency(src, dst);
998 latency = (*(common_father->get_latency)) (common_father, src, dst);
1000 xbt_assert2(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst);
1001 xbt_dynar_free(&elem_father_list);
1007 * \brief Recursive function for finalize
1009 * \param rc the source host name
1011 * This fuction is call by "finalize". It allow to finalize the
1012 * AS or routing components. It delete all the structures.
1014 static void _finalize(routing_component_t rc)
1017 xbt_dict_cursor_t cursor = NULL;
1019 routing_component_t elem;
1020 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
1023 xbt_dict_t tmp_sons = rc->routing_sons;
1024 char *tmp_name = rc->name;
1025 xbt_dict_free(&tmp_sons);
1027 xbt_assert1(rc->finalize, "no defined method \"finalize\" in \"%s\"",
1028 current_routing->name);
1029 (*(rc->finalize)) (rc);
1034 * \brief Generic method: delete all the routing structures
1036 * walk through the routing components tree and delete the structures
1037 * by calling the differents "finalize" functions in each routing component
1039 static void finalize(void)
1041 /* delete recursibly all the tree */
1042 _finalize(global_routing->root);
1043 /* delete last_route */
1044 xbt_dynar_free(&(global_routing->last_route));
1045 /* delete global routing structure */
1046 xbt_free(global_routing);
1049 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
1051 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1053 //adding my one link routes
1056 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
1058 xbt_dynar_foreach(onelink_mine, cpt, link) {
1059 xbt_dynar_push(ret, &link);
1064 xbt_dict_cursor_t cursor = NULL;
1065 routing_component_t rc_child;
1066 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
1067 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
1068 if (onelink_child) {
1069 xbt_dynar_foreach(onelink_child, cpt, link) {
1070 xbt_dynar_push(ret, &link);
1077 static xbt_dynar_t get_onelink_routes(void)
1079 return recursive_get_onelink_routes(global_routing->root);
1082 e_surf_network_element_type_t get_network_element_type(const char
1085 network_element_info_t rc = NULL;
1087 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
1088 if(rc) return rc->rc_type;
1090 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
1091 if(rc) return rc->rc_type;
1093 return SURF_NETWORK_ELEMENT_NULL;
1097 * \brief Generic method: create the global routing schema
1099 * Make a global routing structure and set all the parsing functions.
1101 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
1103 /* config the uniq global routing */
1104 global_routing = xbt_new0(s_routing_global_t, 1);
1105 global_routing->root = NULL;
1106 global_routing->get_route = get_route;
1107 global_routing->get_latency = get_latency;
1108 global_routing->get_route_no_cleanup = get_route_no_cleanup;
1109 global_routing->get_onelink_routes = get_onelink_routes;
1110 global_routing->get_network_element_type = get_network_element_type;
1111 global_routing->finalize = finalize;
1112 global_routing->loopback = loopback;
1113 global_routing->size_of_link = size_of_links;
1114 global_routing->last_route = NULL;
1115 get_link_latency = get_link_latency_fun;
1116 /* no current routing at moment */
1117 current_routing = NULL;
1119 /* parse generic elements */
1120 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
1121 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
1122 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
1124 surfxml_add_callback(STag_surfxml_route_cb_list,
1125 &parse_S_route_new_and_endpoints_XML);
1126 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
1127 &parse_S_ASroute_new_and_endpoints);
1128 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
1129 &parse_S_bypassRoute_new_and_endpoints);
1131 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
1132 &parse_E_link_ctn_new_elem_XML);
1134 surfxml_add_callback(ETag_surfxml_route_cb_list,
1135 &parse_E_route_store_route);
1136 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
1137 &parse_E_ASroute_store_route);
1138 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
1139 &parse_E_bypassRoute_store_route);
1141 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
1142 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
1144 surfxml_add_callback(STag_surfxml_cluster_cb_list,
1145 &routing_parse_Scluster);
1147 surfxml_add_callback(STag_surfxml_peer_cb_list,
1148 &routing_parse_Speer);
1150 surfxml_add_callback(ETag_surfxml_platform_cb_list,
1151 &clean_dict_random);
1154 instr_routing_define_callbacks();
1158 void surf_parse_add_callback_config(void)
1160 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1161 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1162 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
1163 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
1164 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1167 void surf_parse_models_setup()
1169 routing_parse_Erandom();
1170 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1171 surf_config_models_setup(platform_filename);
1172 free(platform_filename);
1175 /* ************************************************************************** */
1176 /* *************************** FULL ROUTING ********************************* */
1178 #define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
1180 /* Routing model structure */
1183 s_routing_component_t generic_routing;
1184 route_extended_t *routing_table;
1185 } s_routing_component_full_t, *routing_component_full_t;
1187 /* Business methods */
1188 static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
1190 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1192 routing_component_full_t routing = (routing_component_full_t) rc;
1193 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1194 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1195 char *k1, *d1, *k2, *d2;
1196 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1197 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1198 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k1);
1199 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k2);
1202 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1204 route_extended_t route = TO_ROUTE_FULL(*src_id, *dst_id);
1206 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1208 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1210 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1211 onelink->link_ptr = link;
1212 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1213 onelink->src = xbt_strdup(k1);
1214 onelink->dst = xbt_strdup(k2);
1215 } else if (routing->generic_routing.hierarchy ==
1216 SURF_ROUTING_RECURSIVE) {
1217 onelink->src = xbt_strdup(route->src_gateway);
1218 onelink->dst = xbt_strdup(route->dst_gateway);
1220 xbt_dynar_push(ret, &onelink);
1228 static route_extended_t full_get_route(routing_component_t rc,
1229 const char *src, const char *dst)
1231 xbt_assert1(rc && src
1233 "Invalid params for \"get_route\" function at AS \"%s\"",
1236 /* set utils vars */
1237 routing_component_full_t routing = (routing_component_full_t) rc;
1238 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1240 generic_src_dst_check(rc, src, dst);
1241 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1242 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1245 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1248 route_extended_t e_route = NULL;
1249 route_extended_t new_e_route = NULL;
1251 unsigned int cpt = 0;
1253 e_route = TO_ROUTE_FULL(*src_id, *dst_id);
1256 new_e_route = xbt_new0(s_route_extended_t, 1);
1257 new_e_route->src_gateway = xbt_strdup(e_route->src_gateway);
1258 new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway);
1259 new_e_route->generic_route.link_list =
1260 xbt_dynar_new(global_routing->size_of_link, NULL);
1261 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
1262 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1268 static void full_finalize(routing_component_t rc)
1270 routing_component_full_t routing = (routing_component_full_t) rc;
1271 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1274 /* Delete routing table */
1275 for (i = 0; i < table_size; i++)
1276 for (j = 0; j < table_size; j++)
1277 generic_free_extended_route(TO_ROUTE_FULL(i, j));
1278 xbt_free(routing->routing_table);
1279 /* Delete bypass dict */
1280 xbt_dict_free(&rc->bypassRoutes);
1281 /* Delete index dict */
1282 xbt_dict_free(&rc->to_index);
1283 /* Delete structure */
1288 /* Creation routing model functions */
1290 static void *model_full_create(void)
1292 routing_component_full_t new_component =
1293 xbt_new0(s_routing_component_full_t, 1);
1294 new_component->generic_routing.set_processing_unit =
1295 generic_set_processing_unit;
1296 new_component->generic_routing.set_autonomous_system =
1297 generic_set_autonomous_system;
1298 new_component->generic_routing.set_route = model_full_set_route;
1299 new_component->generic_routing.set_ASroute = model_full_set_route;
1300 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1301 new_component->generic_routing.get_route = full_get_route;
1302 new_component->generic_routing.get_latency = generic_get_link_latency;
1303 new_component->generic_routing.get_onelink_routes =
1304 full_get_onelink_routes;
1305 new_component->generic_routing.get_bypass_route =
1306 generic_get_bypassroute;
1307 new_component->generic_routing.finalize = full_finalize;
1308 new_component->generic_routing.to_index = xbt_dict_new();
1309 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1310 new_component->generic_routing.get_network_element_type = get_network_element_type;
1311 return new_component;
1314 static void model_full_load(void)
1316 /* use "surfxml_add_callback" to add a parse function call */
1319 static void model_full_unload(void)
1321 /* use "surfxml_del_callback" to remove a parse function call */
1324 static void model_full_end(void)
1327 route_extended_t e_route;
1329 /* set utils vars */
1330 routing_component_full_t routing =
1331 ((routing_component_full_t) current_routing);
1332 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1334 /* Create table if necessary */
1335 if(!routing->routing_table)
1336 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1338 /* Add the loopback if needed */
1339 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1340 for (i = 0; i < table_size; i++) {
1341 e_route = TO_ROUTE_FULL(i, i);
1343 e_route = xbt_new0(s_route_extended_t, 1);
1344 e_route->src_gateway = NULL;
1345 e_route->dst_gateway = NULL;
1346 e_route->generic_route.link_list =
1347 xbt_dynar_new(global_routing->size_of_link, NULL);
1348 xbt_dynar_push(e_route->generic_route.link_list,
1349 &global_routing->loopback);
1350 TO_ROUTE_FULL(i, i) = e_route;
1356 static void model_full_set_route(routing_component_t rc, const char *src,
1357 const char *dst, name_route_extended_t route)
1359 int *src_id, *dst_id;
1360 src_id = xbt_dict_get_or_null(rc->to_index, src);
1361 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1362 routing_component_full_t routing = ((routing_component_full_t) rc);
1363 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1366 && dst_id, "Network elements %s or %s not found", src, dst);
1368 xbt_assert2(xbt_dynar_length(route->generic_route.link_list) > 0,
1369 "Invalid count of links, must be greater than zero (%s,%s)",
1372 if(!routing->routing_table)
1373 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1375 if(TO_ROUTE_FULL(*src_id, *dst_id))
1379 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1380 xbt_dynar_foreach(route->generic_route.link_list,i,link_name)
1382 void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1383 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1384 xbt_dynar_push(link_route_to_test,&link);
1386 xbt_assert2(!xbt_dynar_compare(
1387 (void*)TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list,
1388 (void*)link_route_to_test,
1389 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1390 "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);
1394 if(!route->dst_gateway && !route->src_gateway)
1395 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
1397 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1398 route->src_gateway, dst, route->dst_gateway);
1399 if(global_routing->get_network_element_type((const char*)route->dst_gateway) == SURF_NETWORK_ELEMENT_NULL)
1400 xbt_die("The dst_gateway '%s' does not exist!",route->dst_gateway);
1401 if(global_routing->get_network_element_type((const char*)route->src_gateway) == SURF_NETWORK_ELEMENT_NULL)
1402 xbt_die("The src_gateway '%s' does not exist!",route->src_gateway);
1404 TO_ROUTE_FULL(*src_id, *dst_id) = generic_new_extended_route(rc->hierarchy,route,1);
1405 xbt_dynar_shrink(TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list, 0);
1408 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1409 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1411 if(route->dst_gateway && route->src_gateway)
1413 char *gw_src = xbt_strdup(route->src_gateway);
1414 char *gw_dst = xbt_strdup(route->dst_gateway);
1415 route->src_gateway = gw_dst;
1416 route->dst_gateway = gw_src;
1418 if(TO_ROUTE_FULL(*dst_id, *src_id))
1422 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1423 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1425 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1426 void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1427 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1428 xbt_dynar_push(link_route_to_test,&link);
1430 xbt_assert2(!xbt_dynar_compare(
1431 (void*)TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list,
1432 (void*)link_route_to_test,
1433 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1434 "The route between \"%s\" and \"%s\" already exists", src,dst);
1438 if(!route->dst_gateway && !route->src_gateway)
1439 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
1441 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1442 route->src_gateway, src, route->dst_gateway);
1443 TO_ROUTE_FULL(*dst_id, *src_id) = generic_new_extended_route(rc->hierarchy,route,0);
1444 xbt_dynar_shrink(TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list, 0);
1450 /* ************************************************************************** */
1451 /* *************************** FLOYD ROUTING ******************************** */
1453 #define TO_FLOYD_COST(i,j) (routing->cost_table)[(i)+(j)*table_size]
1454 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
1455 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
1457 /* Routing model structure */
1460 s_routing_component_t generic_routing;
1461 /* vars for calculate the floyd algorith. */
1462 int *predecessor_table;
1464 route_extended_t *link_table; /* char* -> int* */
1465 } s_routing_component_floyd_t, *routing_component_floyd_t;
1467 static route_extended_t floyd_get_route(routing_component_t rc,
1468 const char *src, const char *dst);
1470 /* Business methods */
1471 static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
1473 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1475 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1476 //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1477 xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1478 char *k1, *d1, *k2, *d2;
1479 xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1480 xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1481 route_extended_t route = floyd_get_route(rc, k1, k2);
1483 if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1485 *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1487 onelink_t onelink = xbt_new0(s_onelink_t, 1);
1488 onelink->link_ptr = link;
1489 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1490 onelink->src = xbt_strdup(k1);
1491 onelink->dst = xbt_strdup(k2);
1492 } else if (routing->generic_routing.hierarchy ==
1493 SURF_ROUTING_RECURSIVE) {
1494 onelink->src = xbt_strdup(route->src_gateway);
1495 onelink->dst = xbt_strdup(route->dst_gateway);
1497 xbt_dynar_push(ret, &onelink);
1505 static route_extended_t floyd_get_route(routing_component_t rc,
1506 const char *src, const char *dst)
1508 xbt_assert1(rc && src
1510 "Invalid params for \"get_route\" function at AS \"%s\"",
1513 /* set utils vars */
1514 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1515 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1517 generic_src_dst_check(rc, src, dst);
1518 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1519 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1522 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
1525 /* create a result route */
1526 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1527 new_e_route->generic_route.link_list =
1528 xbt_dynar_new(global_routing->size_of_link, NULL);
1529 new_e_route->src_gateway = NULL;
1530 new_e_route->dst_gateway = NULL;
1535 char *gw_src = NULL, *gw_dst =
1536 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1543 pred = TO_FLOYD_PRED(*src_id, pred);
1544 if (pred == -1) /* if no pred in route -> no route to host */
1546 xbt_assert2(TO_FLOYD_LINK(pred, prev_pred),
1547 "Invalid link for the route between \"%s\" or \"%s\"", src,
1550 prev_gw_src = gw_src;
1551 prev_gw_dst = gw_dst;
1553 route_extended_t e_route = TO_FLOYD_LINK(pred, prev_pred);
1554 gw_src = e_route->src_gateway;
1555 gw_dst = e_route->dst_gateway;
1560 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && !first
1561 && strcmp(gw_dst, prev_gw_src)) {
1562 xbt_dynar_t e_route_as_to_as =
1563 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1564 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1565 gw_dst, prev_gw_src);
1566 links = e_route_as_to_as;
1568 xbt_dynar_foreach(links, cpt, link) {
1569 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1575 links = e_route->generic_route.link_list;
1576 xbt_dynar_foreach(links, cpt, link) {
1577 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1581 } while (pred != *src_id);
1582 xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")",
1583 *src_id, *dst_id, src, dst);
1585 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1586 new_e_route->src_gateway = xbt_strdup(gw_src);
1587 new_e_route->dst_gateway = xbt_strdup(first_gw);
1593 static void floyd_finalize(routing_component_t rc)
1595 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1599 table_size = xbt_dict_length(routing->generic_routing.to_index);
1600 /* Delete link_table */
1601 for (i = 0; i < table_size; i++)
1602 for (j = 0; j < table_size; j++)
1603 generic_free_extended_route(TO_FLOYD_LINK(i, j));
1604 xbt_free(routing->link_table);
1605 /* Delete bypass dict */
1606 xbt_dict_free(&routing->generic_routing.bypassRoutes);
1607 /* Delete index dict */
1608 xbt_dict_free(&(routing->generic_routing.to_index));
1609 /* Delete dictionary index dict, predecessor and links table */
1610 xbt_free(routing->predecessor_table);
1611 /* Delete structure */
1616 static void *model_floyd_create(void)
1618 routing_component_floyd_t new_component =
1619 xbt_new0(s_routing_component_floyd_t, 1);
1620 new_component->generic_routing.set_processing_unit =
1621 generic_set_processing_unit;
1622 new_component->generic_routing.set_autonomous_system =
1623 generic_set_autonomous_system;
1624 new_component->generic_routing.set_route = model_floyd_set_route;
1625 new_component->generic_routing.set_ASroute = model_floyd_set_route;
1626 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1627 new_component->generic_routing.get_route = floyd_get_route;
1628 new_component->generic_routing.get_latency = generic_get_link_latency;
1629 new_component->generic_routing.get_onelink_routes =
1630 floyd_get_onelink_routes;
1631 new_component->generic_routing.get_bypass_route =
1632 generic_get_bypassroute;
1633 new_component->generic_routing.finalize = floyd_finalize;
1634 new_component->generic_routing.to_index = xbt_dict_new();
1635 new_component->generic_routing.bypassRoutes = xbt_dict_new();
1636 new_component->generic_routing.get_network_element_type = get_network_element_type;
1637 return new_component;
1640 static void model_floyd_load(void)
1642 /* use "surfxml_add_callback" to add a parse function call */
1645 static void model_floyd_unload(void)
1647 /* use "surfxml_del_callback" to remove a parse function call */
1650 static void model_floyd_end(void)
1653 routing_component_floyd_t routing =
1654 ((routing_component_floyd_t) current_routing);
1656 unsigned int i, j, a, b, c;
1658 /* set the size of table routing */
1659 size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1661 if(!routing->link_table)
1663 /* Create Cost, Predecessor and Link tables */
1664 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1665 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1666 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1668 /* Initialize costs and predecessors */
1669 for (i = 0; i < table_size; i++)
1670 for (j = 0; j < table_size; j++) {
1671 TO_FLOYD_COST(i, j) = DBL_MAX;
1672 TO_FLOYD_PRED(i, j) = -1;
1673 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1677 /* Add the loopback if needed */
1678 if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1679 for (i = 0; i < table_size; i++) {
1680 route_extended_t e_route = TO_FLOYD_LINK(i, i);
1682 e_route = xbt_new0(s_route_extended_t, 1);
1683 e_route->src_gateway = NULL;
1684 e_route->dst_gateway = NULL;
1685 e_route->generic_route.link_list =
1686 xbt_dynar_new(global_routing->size_of_link, NULL);
1687 xbt_dynar_push(e_route->generic_route.link_list,
1688 &global_routing->loopback);
1689 TO_FLOYD_LINK(i, i) = e_route;
1690 TO_FLOYD_PRED(i, i) = i;
1691 TO_FLOYD_COST(i, i) = 1;
1695 /* Calculate path costs */
1696 for (c = 0; c < table_size; c++) {
1697 for (a = 0; a < table_size; a++) {
1698 for (b = 0; b < table_size; b++) {
1699 if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
1700 if (TO_FLOYD_COST(a, b) == DBL_MAX ||
1701 (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
1702 TO_FLOYD_COST(a, b))) {
1703 TO_FLOYD_COST(a, b) =
1704 TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
1705 TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
1713 static void model_floyd_set_route(routing_component_t rc, const char *src,
1714 const char *dst, name_route_extended_t route)
1716 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1718 /* set the size of table routing */
1719 size_t table_size = xbt_dict_length(rc->to_index);
1720 int *src_id, *dst_id;
1723 src_id = xbt_dict_get_or_null(rc->to_index, src);
1724 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1726 if(!routing->link_table)
1728 /* Create Cost, Predecessor and Link tables */
1729 routing->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
1730 routing->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */
1731 routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */
1733 /* Initialize costs and predecessors */
1734 for (i = 0; i < table_size; i++)
1735 for (j = 0; j < table_size; j++) {
1736 TO_FLOYD_COST(i, j) = DBL_MAX;
1737 TO_FLOYD_PRED(i, j) = -1;
1738 TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */
1742 if(TO_FLOYD_LINK(*src_id, *dst_id))
1744 if(!route->dst_gateway && !route->src_gateway)
1745 XBT_DEBUG("See Route from \"%s\" to \"%s\"", src, dst);
1747 XBT_DEBUG("See ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1748 route->src_gateway, dst, route->dst_gateway);
1751 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1752 xbt_dynar_foreach(route->generic_route.link_list,cpt,link_name)
1754 void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1755 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1756 xbt_dynar_push(link_route_to_test,&link);
1758 xbt_assert2(!xbt_dynar_compare(
1759 (void*)TO_FLOYD_LINK(*src_id, *dst_id)->generic_route.link_list,
1760 (void*)link_route_to_test,
1761 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1762 "The route between \"%s\" and \"%s\" already exists", src,dst);
1766 if(!route->dst_gateway && !route->src_gateway)
1767 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
1769 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1770 route->src_gateway, dst, route->dst_gateway);
1771 if(global_routing->get_network_element_type((const char*)route->dst_gateway) == SURF_NETWORK_ELEMENT_NULL)
1772 xbt_die("The dst_gateway '%s' does not exist!",route->dst_gateway);
1773 if(global_routing->get_network_element_type((const char*)route->src_gateway) == SURF_NETWORK_ELEMENT_NULL)
1774 xbt_die("The src_gateway '%s' does not exist!",route->src_gateway);
1776 TO_FLOYD_LINK(*src_id, *dst_id) =
1777 generic_new_extended_route(rc->hierarchy, route, 1);
1778 TO_FLOYD_PRED(*src_id, *dst_id) = *src_id;
1779 TO_FLOYD_COST(*src_id, *dst_id) =
1780 ((TO_FLOYD_LINK(*src_id, *dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1783 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
1784 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
1786 if(TO_FLOYD_LINK(*dst_id, *src_id))
1788 if(!route->dst_gateway && !route->src_gateway)
1789 XBT_DEBUG("See Route from \"%s\" to \"%s\"", dst, src);
1791 XBT_DEBUG("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1792 route->src_gateway, src, route->dst_gateway);
1795 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1796 for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1798 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1799 void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1800 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1801 xbt_dynar_push(link_route_to_test,&link);
1803 xbt_assert2(!xbt_dynar_compare(
1804 (void*)TO_FLOYD_LINK(*dst_id, *src_id)->generic_route.link_list,
1805 (void*)link_route_to_test,
1806 (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1807 "The route between \"%s\" and \"%s\" already exists", src,dst);
1811 if(route->dst_gateway && route->src_gateway)
1813 char *gw_src = xbt_strdup(route->src_gateway);
1814 char *gw_dst = xbt_strdup(route->dst_gateway);
1815 route->src_gateway = gw_dst;
1816 route->dst_gateway = gw_src;
1819 if(!route->dst_gateway && !route->src_gateway)
1820 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
1822 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1823 route->src_gateway, src, route->dst_gateway);
1825 TO_FLOYD_LINK(*dst_id, *src_id) =
1826 generic_new_extended_route(rc->hierarchy, route, 0);
1827 TO_FLOYD_PRED(*dst_id, *src_id) = *dst_id;
1828 TO_FLOYD_COST(*dst_id, *src_id) =
1829 ((TO_FLOYD_LINK(*dst_id, *src_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
1834 /* ************************************************************************** */
1835 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1838 s_routing_component_t generic_routing;
1839 xbt_graph_t route_graph; /* xbt_graph */
1840 xbt_dict_t graph_node_map; /* map */
1841 xbt_dict_t route_cache; /* use in cache mode */
1843 } s_routing_component_dijkstra_t, *routing_component_dijkstra_t;
1846 typedef struct graph_node_data {
1848 int graph_id; /* used for caching internal graph id's */
1849 } s_graph_node_data_t, *graph_node_data_t;
1851 typedef struct graph_node_map_element {
1853 } s_graph_node_map_element_t, *graph_node_map_element_t;
1855 typedef struct route_cache_element {
1858 } s_route_cache_element_t, *route_cache_element_t;
1860 /* Free functions */
1862 static void route_cache_elem_free(void *e)
1864 route_cache_element_t elm = (route_cache_element_t) e;
1866 xbt_free(elm->pred_arr);
1871 static void graph_node_map_elem_free(void *e)
1873 graph_node_map_element_t elm = (graph_node_map_element_t) e;
1879 static void graph_edge_data_free(void *e)
1881 route_extended_t e_route = (route_extended_t) e;
1883 xbt_dynar_free(&(e_route->generic_route.link_list));
1884 if (e_route->src_gateway)
1885 xbt_free(e_route->src_gateway);
1886 if (e_route->dst_gateway)
1887 xbt_free(e_route->dst_gateway);
1892 /* Utility functions */
1894 static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc,
1895 int id, int graph_id)
1897 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1898 xbt_node_t node = NULL;
1899 graph_node_data_t data = NULL;
1900 graph_node_map_element_t elm = NULL;
1902 data = xbt_new0(struct graph_node_data, 1);
1904 data->graph_id = graph_id;
1905 node = xbt_graph_new_node(routing->route_graph, data);
1907 elm = xbt_new0(struct graph_node_map_element, 1);
1909 xbt_dict_set_ext(routing->graph_node_map, (char *) (&id), sizeof(int),
1910 (xbt_set_elm_t) elm, &graph_node_map_elem_free);
1915 static graph_node_map_element_t
1916 graph_node_map_search(routing_component_dijkstra_t rc, int id)
1918 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1919 graph_node_map_element_t elm = (graph_node_map_element_t)
1920 xbt_dict_get_or_null_ext(routing->graph_node_map,
1928 static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id,
1929 int dst_id, route_extended_t e_route)
1931 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1932 XBT_DEBUG("Load Route from \"%d\" to \"%d\"", src_id, dst_id);
1933 xbt_node_t src = NULL;
1934 xbt_node_t dst = NULL;
1936 graph_node_map_element_t src_elm = (graph_node_map_element_t)
1937 xbt_dict_get_or_null_ext(routing->graph_node_map,
1940 graph_node_map_element_t dst_elm = (graph_node_map_element_t)
1941 xbt_dict_get_or_null_ext(routing->graph_node_map,
1947 src = src_elm->node;
1950 dst = dst_elm->node;
1952 /* add nodes if they don't exist in the graph */
1953 if (src_id == dst_id && src == NULL && dst == NULL) {
1954 src = route_graph_new_node(rc, src_id, -1);
1958 src = route_graph_new_node(rc, src_id, -1);
1961 dst = route_graph_new_node(rc, dst_id, -1);
1965 /* add link as edge to graph */
1966 xbt_graph_new_edge(routing->route_graph, src, dst, e_route);
1969 static void add_loopback_dijkstra(routing_component_dijkstra_t rc)
1971 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1973 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1975 xbt_node_t node = NULL;
1976 unsigned int cursor2;
1977 xbt_dynar_foreach(nodes, cursor2, node) {
1978 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1979 xbt_edge_t edge = NULL;
1980 unsigned int cursor;
1983 xbt_dynar_foreach(out_edges, cursor, edge) {
1984 xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1985 if (other_node == node) {
1992 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
1993 e_route->src_gateway = NULL;
1994 e_route->dst_gateway = NULL;
1995 e_route->generic_route.link_list =
1996 xbt_dynar_new(global_routing->size_of_link, NULL);
1997 xbt_dynar_push(e_route->generic_route.link_list,
1998 &global_routing->loopback);
1999 xbt_graph_new_edge(routing->route_graph, node, node, e_route);
2004 /* Business methods */
2005 static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
2007 xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
2010 static route_extended_t dijkstra_get_route(routing_component_t rc,
2014 xbt_assert1(rc && src
2016 "Invalid params for \"get_route\" function at AS \"%s\"",
2019 /* set utils vars */
2020 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2022 generic_src_dst_check(rc, src, dst);
2023 int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
2024 int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
2027 "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
2030 /* create a result route */
2031 route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
2032 new_e_route->generic_route.link_list =
2033 xbt_dynar_new(global_routing->size_of_link, NULL);
2034 new_e_route->src_gateway = NULL;
2035 new_e_route->dst_gateway = NULL;
2037 int *pred_arr = NULL;
2038 int src_node_id = 0;
2039 int dst_node_id = 0;
2042 route_extended_t e_route;
2046 xbt_dynar_t links = NULL;
2047 route_cache_element_t elm = NULL;
2048 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
2050 /* Use the graph_node id mapping set to quickly find the nodes */
2051 graph_node_map_element_t src_elm =
2052 graph_node_map_search(routing, *src_id);
2053 graph_node_map_element_t dst_elm =
2054 graph_node_map_search(routing, *dst_id);
2055 xbt_assert2(src_elm != NULL
2056 && dst_elm != NULL, "src %d or dst %d does not exist",
2058 src_node_id = ((graph_node_data_t)
2059 xbt_graph_node_get_data(src_elm->node))->graph_id;
2060 dst_node_id = ((graph_node_data_t)
2061 xbt_graph_node_get_data(dst_elm->node))->graph_id;
2063 /* if the src and dst are the same *//* fixed, missing in the previous version */
2064 if (src_node_id == dst_node_id) {
2066 xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
2067 xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
2069 xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v);
2071 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
2074 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
2076 links = e_route->generic_route.link_list;
2077 xbt_dynar_foreach(links, cpt, link) {
2078 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
2084 if (routing->cached) {
2085 /*check if there is a cached predecessor list avail */
2086 elm = (route_cache_element_t)
2087 xbt_dict_get_or_null_ext(routing->route_cache, (char *) (&src_id),
2091 if (elm) { /* cached mode and cache hit */
2092 pred_arr = elm->pred_arr;
2093 } else { /* not cached mode or cache miss */
2094 double *cost_arr = NULL;
2095 xbt_heap_t pqueue = NULL;
2098 int nr_nodes = xbt_dynar_length(nodes);
2099 cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
2100 pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
2101 pqueue = xbt_heap_new(nr_nodes, xbt_free);
2104 cost_arr[src_node_id] = 0.0;
2106 for (i = 0; i < nr_nodes; i++) {
2107 if (i != src_node_id) {
2108 cost_arr[i] = DBL_MAX;
2113 /* initialize priority queue */
2114 nodeid = xbt_new0(int, 1);
2116 xbt_heap_push(pqueue, nodeid, cost_arr[i]);
2120 /* apply dijkstra using the indexes from the graph's node array */
2121 while (xbt_heap_size(pqueue) > 0) {
2122 int *v_id = xbt_heap_pop(pqueue);
2123 xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
2124 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
2125 xbt_edge_t edge = NULL;
2126 unsigned int cursor;
2128 xbt_dynar_foreach(out_edges, cursor, edge) {
2129 xbt_node_t u_node = xbt_graph_edge_get_target(edge);
2130 graph_node_data_t data = xbt_graph_node_get_data(u_node);
2131 int u_id = data->graph_id;
2132 route_extended_t tmp_e_route =
2133 (route_extended_t) xbt_graph_edge_get_data(edge);
2134 int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */
2136 if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
2137 pred_arr[u_id] = *v_id;
2138 cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
2139 nodeid = xbt_new0(int, 1);
2141 xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
2145 /* free item popped from pqueue */
2150 xbt_heap_free(pqueue);
2153 /* compose route path with links */
2154 char *gw_src = NULL, *gw_dst =
2155 NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
2157 for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
2158 xbt_node_t node_pred_v =
2159 xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
2160 xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
2162 xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
2164 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
2167 prev_gw_src = gw_src;
2168 prev_gw_dst = gw_dst;
2170 e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
2171 gw_src = e_route->src_gateway;
2172 gw_dst = e_route->dst_gateway;
2174 if (v == dst_node_id)
2177 if (rc->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
2178 && strcmp(gw_dst, prev_gw_src)) {
2179 xbt_dynar_t e_route_as_to_as =
2180 (*(global_routing->get_route)) (gw_dst, prev_gw_src);
2181 xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
2182 gw_dst, prev_gw_src);
2183 links = e_route_as_to_as;
2185 xbt_dynar_foreach(links, cpt, link) {
2186 xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
2192 links = e_route->generic_route.link_list;
2193 xbt_dynar_foreach(links, cpt, link) {
2194 xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
2199 if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
2200 new_e_route->src_gateway = xbt_strdup(gw_src);
2201 new_e_route->dst_gateway = xbt_strdup(first_gw);
2204 if (routing->cached && elm == NULL) {
2205 /* add to predecessor list of the current src-host to cache */
2206 elm = xbt_new0(struct route_cache_element, 1);
2207 elm->pred_arr = pred_arr;
2209 xbt_dict_set_ext(routing->route_cache, (char *) (&src_id), sizeof(int),
2210 (xbt_set_elm_t) elm, &route_cache_elem_free);
2213 if (!routing->cached)
2219 static void dijkstra_finalize(routing_component_t rc)
2221 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2224 xbt_graph_free_graph(routing->route_graph, &xbt_free,
2225 &graph_edge_data_free, &xbt_free);
2226 xbt_dict_free(&routing->graph_node_map);
2227 if (routing->cached)
2228 xbt_dict_free(&routing->route_cache);
2229 /* Delete bypass dict */
2230 xbt_dict_free(&routing->generic_routing.bypassRoutes);
2231 /* Delete index dict */
2232 xbt_dict_free(&(routing->generic_routing.to_index));
2233 /* Delete structure */
2238 /* Creation routing model functions */
2240 static void *model_dijkstra_both_create(int cached)
2242 routing_component_dijkstra_t new_component =
2243 xbt_new0(s_routing_component_dijkstra_t, 1);
2244 new_component->generic_routing.set_processing_unit =
2245 generic_set_processing_unit;
2246 new_component->generic_routing.set_autonomous_system =
2247 generic_set_autonomous_system;
2248 new_component->generic_routing.set_route = model_dijkstra_both_set_route;
2249 new_component->generic_routing.set_ASroute = model_dijkstra_both_set_route;
2250 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
2251 new_component->generic_routing.get_route = dijkstra_get_route;
2252 new_component->generic_routing.get_latency = generic_get_link_latency;
2253 new_component->generic_routing.get_onelink_routes =
2254 dijkstra_get_onelink_routes;
2255 new_component->generic_routing.get_bypass_route =
2256 generic_get_bypassroute;
2257 new_component->generic_routing.finalize = dijkstra_finalize;
2258 new_component->cached = cached;
2259 new_component->generic_routing.to_index = xbt_dict_new();
2260 new_component->generic_routing.bypassRoutes = xbt_dict_new();
2261 new_component->generic_routing.get_network_element_type = get_network_element_type;
2262 return new_component;
2265 static void *model_dijkstra_create(void)
2267 return model_dijkstra_both_create(0);
2270 static void *model_dijkstracache_create(void)
2272 return model_dijkstra_both_create(1);
2275 static void model_dijkstra_both_load(void)
2277 /* use "surfxml_add_callback" to add a parse function call */
2280 static void model_dijkstra_both_unload(void)
2282 /* use "surfxml_del_callback" to remove a parse function call */
2285 static void model_dijkstra_both_end(void)
2287 routing_component_dijkstra_t routing =
2288 (routing_component_dijkstra_t) current_routing;
2290 xbt_node_t node = NULL;
2291 unsigned int cursor2;
2292 xbt_dynar_t nodes = NULL;
2294 /* Create the topology graph */
2295 if(!routing->route_graph)
2296 routing->route_graph = xbt_graph_new_graph(1, NULL);
2297 if(!routing->graph_node_map)
2298 routing->graph_node_map = xbt_dict_new();
2300 if (routing->cached && !routing->route_cache)
2301 routing->route_cache = xbt_dict_new();
2303 /* Add the loopback if needed */
2304 if (current_routing->hierarchy == SURF_ROUTING_BASE)
2305 add_loopback_dijkstra(routing);
2307 /* initialize graph indexes in nodes after graph has been built */
2308 nodes = xbt_graph_get_nodes(routing->route_graph);
2310 xbt_dynar_foreach(nodes, cursor2, node) {
2311 graph_node_data_t data = xbt_graph_node_get_data(node);
2312 data->graph_id = cursor2;
2316 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
2317 const char *dst, name_route_extended_t route)
2319 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
2320 int *src_id, *dst_id;
2321 src_id = xbt_dict_get_or_null(rc->to_index, src);
2322 dst_id = xbt_dict_get_or_null(rc->to_index, dst);
2324 /* Create the topology graph */
2325 if(!routing->route_graph)
2326 routing->route_graph = xbt_graph_new_graph(1, NULL);
2327 if(!routing->graph_node_map)
2328 routing->graph_node_map = xbt_dict_new();
2330 if (routing->cached && !routing->route_cache)
2331 routing->route_cache = xbt_dict_new();
2333 if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
2334 || A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
2335 xbt_die("Route symmetrical not supported on model dijkstra");
2337 if(!route->dst_gateway && !route->src_gateway)
2338 XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
2340 XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
2341 route->src_gateway, dst, route->dst_gateway);
2342 if(global_routing->get_network_element_type((const char*)route->dst_gateway) == SURF_NETWORK_ELEMENT_NULL)
2343 xbt_die("The dst_gateway '%s' does not exist!",route->dst_gateway);
2344 if(global_routing->get_network_element_type((const char*)route->src_gateway) == SURF_NETWORK_ELEMENT_NULL)
2345 xbt_die("The src_gateway '%s' does not exist!",route->src_gateway);
2348 route_extended_t e_route =
2349 generic_new_extended_route(current_routing->hierarchy, route, 1);
2350 route_new_dijkstra(routing, *src_id, *dst_id, e_route);
2353 #ifdef HAVE_PCRE_LIB
2354 /* ************************************************** */
2355 /* ************** RULE-BASED ROUTING **************** */
2357 /* Routing model structure */
2360 s_routing_component_t generic_routing;
2361 xbt_dict_t dict_processing_units;
2362 xbt_dict_t dict_autonomous_systems;
2363 xbt_dynar_t list_route;
2364 xbt_dynar_t list_ASroute;
2365 } s_routing_component_rulebased_t, *routing_component_rulebased_t;
2367 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
2368 typedef struct s_rule_route_extended s_rule_route_extended_t,
2369 *rule_route_extended_t;
2371 struct s_rule_route {
2372 xbt_dynar_t re_str_link; // dynar of char*
2377 struct s_rule_route_extended {
2378 s_rule_route_t generic_rule_route;
2379 char *re_src_gateway;
2380 char *re_dst_gateway;
2383 static void rule_route_free(void *e)
2385 rule_route_t *elem = (rule_route_t *) (e);
2387 xbt_dynar_free(&(*elem)->re_str_link);
2388 pcre_free((*elem)->re_src);
2389 pcre_free((*elem)->re_dst);
2395 static void rule_route_extended_free(void *e)
2397 rule_route_extended_t *elem = (rule_route_extended_t *) e;
2399 xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link);
2400 pcre_free((*elem)->generic_rule_route.re_src);
2401 pcre_free((*elem)->generic_rule_route.re_dst);
2402 xbt_free((*elem)->re_src_gateway);
2403 xbt_free((*elem)->re_dst_gateway);
2408 /* Parse routing model functions */
2410 static void model_rulebased_set_processing_unit(routing_component_t rc,
2413 routing_component_rulebased_t routing =
2414 (routing_component_rulebased_t) rc;
2415 xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
2418 static void model_rulebased_set_autonomous_system(routing_component_t rc,
2421 routing_component_rulebased_t routing =
2422 (routing_component_rulebased_t) rc;
2423 xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
2427 static void model_rulebased_set_route(routing_component_t rc,
2428 const char *src, const char *dst,
2429 name_route_extended_t route)
2431 routing_component_rulebased_t routing =
2432 (routing_component_rulebased_t) rc;
2433 rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
2436 ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL);
2437 xbt_assert3(ruleroute->re_src,
2438 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2439 erroffset, src, error);
2440 ruleroute->re_dst = pcre_compile(dst, 0, &error, &erroffset, NULL);
2441 xbt_assert3(ruleroute->re_src,
2442 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2443 erroffset, dst, error);
2444 ruleroute->re_str_link = route->generic_route.link_list;
2445 xbt_dynar_push(routing->list_route, &ruleroute);
2449 static void model_rulebased_set_ASroute(routing_component_t rc,
2450 const char *src, const char *dst,
2451 name_route_extended_t route)
2453 routing_component_rulebased_t routing =
2454 (routing_component_rulebased_t) rc;
2455 rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
2458 ruleroute_e->generic_rule_route.re_src =
2459 pcre_compile(src, 0, &error, &erroffset, NULL);
2460 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2461 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2462 erroffset, src, error);
2463 ruleroute_e->generic_rule_route.re_dst =
2464 pcre_compile(dst, 0, &error, &erroffset, NULL);
2465 xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2466 "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2467 erroffset, dst, error);
2468 ruleroute_e->generic_rule_route.re_str_link =
2469 route->generic_route.link_list;
2470 ruleroute_e->re_src_gateway = route->src_gateway;
2471 ruleroute_e->re_dst_gateway = route->dst_gateway;
2472 xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
2473 // xbt_free(route->src_gateway);
2474 // xbt_free(route->dst_gateway);
2478 static void model_rulebased_set_bypassroute(routing_component_t rc,
2481 route_extended_t e_route)
2483 xbt_die("bypass routing not supported for Route-Based model");
2486 #define BUFFER_SIZE 4096 /* result buffer size */
2487 #define OVECCOUNT 30 /* should be a multiple of 3 */
2489 static char *remplace(char *value, const char **src_list, int src_size,
2490 const char **dst_list, int dst_size)
2493 char result_result[BUFFER_SIZE];
2494 int i_result_buffer;
2495 int value_length = (int) strlen(value);
2499 i_result_buffer = 0;
2501 if (value[i] == '$') {
2505 int number_length = 0;
2506 while ('0' <= value[i + number_length]
2507 && value[i + number_length] <= '9') {
2510 xbt_assert2(number_length != 0,
2511 "bad string parameter, no number indication, at offset: %d (\"%s\")",
2515 number = atoi(value + i);
2516 i = i + number_length;
2517 xbt_assert2(i + 2 < value_length,
2518 "bad string parameter, too few chars, at offset: %d (\"%s\")",
2521 // solve the indication
2522 const char **param_list;
2524 if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') {
2525 param_list = src_list;
2526 param_size = src_size;
2527 } else if (value[i] == 'd' && value[i + 1] == 's'
2528 && value[i + 2] == 't') {
2529 param_list = dst_list;
2530 param_size = dst_size;
2532 xbt_die("bad string parameter, support only \"src\" and \"dst\", "
2533 "at offset: %d (\"%s\")", i, value);
2537 xbt_assert4(param_size >= number,
2538 "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",
2539 i, value, param_size, number);
2541 const char *param = param_list[number];
2542 int size = strlen(param);
2544 for (cp = 0; cp < size; cp++) {
2545 result_result[i_result_buffer] = param[cp];
2547 if (i_result_buffer >= BUFFER_SIZE)
2551 result_result[i_result_buffer] = value[i];
2556 } while (i < value_length && i_result_buffer < BUFFER_SIZE);
2558 xbt_assert2(i_result_buffer < BUFFER_SIZE,
2559 "solving string \"%s\", small buffer size (%d)", value,
2561 result_result[i_result_buffer] = 0;
2562 return xbt_strdup(result_result);
2565 static route_extended_t rulebased_get_route(routing_component_t rc,
2568 static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
2570 xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
2571 routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
2573 xbt_dict_cursor_t c1 = NULL;
2577 char *router = NULL;
2578 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2579 if (strstr (k1, "router")){
2584 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2587 xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2588 route_extended_t route = rulebased_get_route (rc, router, k1);
2590 int number_of_links = xbt_dynar_length(route->generic_route.link_list);
2591 if (number_of_links != 3) {
2592 xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2596 xbt_dynar_get_cpy (route->generic_route.link_list, 2, &link_ptr);
2597 onelink_t onelink = xbt_new0 (s_onelink_t, 1);
2598 onelink->src = xbt_strdup (k1);
2599 onelink->dst = xbt_strdup (router);
2600 onelink->link_ptr = link_ptr;
2601 xbt_dynar_push (ret, &onelink);
2606 /* Business methods */
2607 static route_extended_t rulebased_get_route(routing_component_t rc,
2611 xbt_assert1(rc && src
2613 "Invalid params for \"get_route\" function at AS \"%s\"",
2616 /* set utils vars */
2617 routing_component_rulebased_t routing =
2618 (routing_component_rulebased_t) rc;
2620 int are_processing_units=0;
2621 xbt_dynar_t rule_list;
2622 if (xbt_dict_get_or_null(routing->dict_processing_units, src)
2623 && xbt_dict_get_or_null(routing->dict_processing_units, dst)) {
2624 are_processing_units = 1;
2625 rule_list = routing->list_route;
2626 } else if (xbt_dict_get_or_null(routing->dict_autonomous_systems, src)
2627 && xbt_dict_get_or_null(routing->dict_autonomous_systems,
2629 are_processing_units = 0;
2630 rule_list = routing->list_ASroute;
2632 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found in "
2633 "the local table", src, dst);
2637 int src_length = (int) strlen(src);
2638 int dst_length = (int) strlen(dst);
2640 xbt_dynar_t links_list =
2641 xbt_dynar_new(global_routing->size_of_link, NULL);
2643 rule_route_t ruleroute;
2645 int ovector_src[OVECCOUNT];
2646 int ovector_dst[OVECCOUNT];
2647 const char **list_src = NULL;
2648 const char **list_dst = NULL;
2650 xbt_dynar_foreach(rule_list, cpt, ruleroute) {
2652 pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0,
2653 ovector_src, OVECCOUNT);
2656 pcre_exec(ruleroute->re_dst, NULL, dst, dst_length, 0, 0,
2657 ovector_dst, OVECCOUNT);
2659 res = pcre_get_substring_list(src, ovector_src, rc_src, &list_src);
2660 xbt_assert1(!res, "error solving substring list for src \"%s\"", src);
2661 res = pcre_get_substring_list(dst, ovector_dst, rc_dst, &list_dst);
2662 xbt_assert1(!res, "error solving substring list for src \"%s\"", dst);
2664 xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) {
2665 char *new_link_name =
2666 remplace(link_name, list_src, rc_src, list_dst, rc_dst);
2668 xbt_lib_get_or_null(link_lib, new_link_name, SURF_LINK_LEVEL);
2670 xbt_dynar_push(links_list, &link);
2672 THROW1(mismatch_error, 0, "Link %s not found", new_link_name);
2673 xbt_free(new_link_name);
2677 if (rc_src >= 0 && rc_dst >= 0)
2681 route_extended_t new_e_route = NULL;
2682 if (rc_src >= 0 && rc_dst >= 0) {
2683 new_e_route = xbt_new0(s_route_extended_t, 1);
2684 new_e_route->generic_route.link_list = links_list;
2685 } else if (!strcmp(src, dst) && are_processing_units) {
2686 new_e_route = xbt_new0(s_route_extended_t, 1);
2687 xbt_dynar_push(links_list, &(global_routing->loopback));
2688 new_e_route->generic_route.link_list = links_list;
2690 xbt_dynar_free(&link_list);
2693 if (!are_processing_units && new_e_route) {
2694 rule_route_extended_t ruleroute_extended =
2695 (rule_route_extended_t) ruleroute;
2696 new_e_route->src_gateway =
2697 remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
2699 new_e_route->dst_gateway =
2700 remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
2705 pcre_free_substring_list(list_src);
2707 pcre_free_substring_list(list_dst);
2712 static route_extended_t rulebased_get_bypass_route(routing_component_t rc,
2719 static void rulebased_finalize(routing_component_t rc)
2721 routing_component_rulebased_t routing =
2722 (routing_component_rulebased_t) rc;
2724 xbt_dict_free(&routing->dict_processing_units);
2725 xbt_dict_free(&routing->dict_autonomous_systems);
2726 xbt_dynar_free(&routing->list_route);
2727 xbt_dynar_free(&routing->list_ASroute);
2728 /* Delete structure */
2733 /* Creation routing model functions */
2734 static void *model_rulebased_create(void)
2736 routing_component_rulebased_t new_component =
2737 xbt_new0(s_routing_component_rulebased_t, 1);
2738 new_component->generic_routing.set_processing_unit =
2739 model_rulebased_set_processing_unit;
2740 new_component->generic_routing.set_autonomous_system =
2741 model_rulebased_set_autonomous_system;
2742 new_component->generic_routing.set_route = model_rulebased_set_route;
2743 new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
2744 new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
2745 new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
2746 new_component->generic_routing.get_route = rulebased_get_route;
2747 new_component->generic_routing.get_latency = generic_get_link_latency;
2748 new_component->generic_routing.get_bypass_route = rulebased_get_bypass_route;
2749 new_component->generic_routing.finalize = rulebased_finalize;
2750 new_component->generic_routing.get_network_element_type = get_network_element_type;
2751 /* initialization of internal structures */
2752 new_component->dict_processing_units = xbt_dict_new();
2753 new_component->dict_autonomous_systems = xbt_dict_new();
2754 new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
2755 new_component->list_ASroute =
2756 xbt_dynar_new(sizeof(rule_route_extended_t),
2757 &rule_route_extended_free);
2758 return new_component;
2761 static void model_rulebased_load(void)
2763 /* use "surfxml_add_callback" to add a parse function call */
2766 static void model_rulebased_unload(void)
2768 /* use "surfxml_del_callback" to remove a parse function call */
2771 static void model_rulebased_end(void)
2775 #endif /* HAVE_PCRE_LIB */
2777 /* ************************************************************************** */
2778 /* ******************************* NO ROUTING ******************************* */
2780 /* Routing model structure */
2782 s_routing_component_t generic_routing;
2783 } s_routing_component_none_t, *routing_component_none_t;
2785 /* Business methods */
2786 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc)
2791 static route_extended_t none_get_route(routing_component_t rc,
2792 const char *src, const char *dst)
2797 static route_extended_t none_get_bypass_route(routing_component_t rc,
2804 static void none_finalize(routing_component_t rc)
2809 static void none_set_processing_unit(routing_component_t rc,
2814 static void none_set_autonomous_system(routing_component_t rc,
2819 /* Creation routing model functions */
2820 static void *model_none_create(void)
2822 routing_component_none_t new_component =
2823 xbt_new0(s_routing_component_none_t, 1);
2824 new_component->generic_routing.set_processing_unit =
2825 none_set_processing_unit;
2826 new_component->generic_routing.set_autonomous_system =
2827 none_set_autonomous_system;
2828 new_component->generic_routing.set_route = NULL;
2829 new_component->generic_routing.set_ASroute = NULL;
2830 new_component->generic_routing.set_bypassroute = NULL;
2831 new_component->generic_routing.get_route = none_get_route;
2832 new_component->generic_routing.get_onelink_routes =
2833 none_get_onelink_routes;
2834 new_component->generic_routing.get_bypass_route = none_get_bypass_route;
2835 new_component->generic_routing.finalize = none_finalize;
2836 return new_component;
2839 static void model_none_load(void)
2843 static void model_none_unload(void)
2847 static void model_none_end(void)
2851 /* ************************************************** */
2852 /* ********** PATERN FOR NEW ROUTING **************** */
2854 /* The minimal configuration of a new routing model need the next functions,
2855 * also you need to set at the start of the file, the new model in the model
2856 * list. Remember keep the null ending of the list.
2858 /*** Routing model structure ***/
2860 // s_routing_component_t generic_routing;
2861 // /* things that your routing model need */
2862 // } s_routing_component_NEW_t,*routing_component_NEW_t;
2864 /*** Parse routing model functions ***/
2865 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
2866 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
2867 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
2868 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
2869 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
2871 /*** Business methods ***/
2872 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2873 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2874 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
2876 /*** Creation routing model functions ***/
2877 // static void* model_NEW_create(void) {
2878 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
2879 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
2880 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
2881 // new_component->generic_routing.set_route = model_NEW_set_route;
2882 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
2883 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
2884 // new_component->generic_routing.get_route = NEW_get_route;
2885 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
2886 // new_component->generic_routing.finalize = NEW_finalize;
2887 // /* initialization of internal structures */
2888 // return new_component;
2889 // } /* mandatory */
2890 // static void model_NEW_load(void) {} /* mandatory */
2891 // static void model_NEW_unload(void) {} /* mandatory */
2892 // static void model_NEW_end(void) {} /* mandatory */
2894 /* ************************************************************************** */
2895 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
2897 static void generic_set_processing_unit(routing_component_t rc,
2900 XBT_DEBUG("Load process unit \"%s\"", name);
2901 int *id = xbt_new0(int, 1);
2902 xbt_dict_t _to_index;
2903 _to_index = current_routing->to_index;
2904 *id = xbt_dict_length(_to_index);
2905 xbt_dict_set(_to_index, name, id, xbt_free);
2908 static void generic_set_autonomous_system(routing_component_t rc,
2911 XBT_DEBUG("Load Autonomous system \"%s\"", name);
2912 int *id = xbt_new0(int, 1);
2913 xbt_dict_t _to_index;
2914 _to_index = current_routing->to_index;
2915 *id = xbt_dict_length(_to_index);
2916 xbt_dict_set(_to_index, name, id, xbt_free);
2919 static int surf_pointer_resource_cmp(const void *a, const void *b)
2924 static int surf_link_resource_cmp(const void *a, const void *b)
2926 return !!memcmp(a,b,global_routing->size_of_link);
2929 static void generic_set_bypassroute(routing_component_t rc,
2930 const char *src, const char *dst,
2931 route_extended_t e_route)
2933 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
2934 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2937 route_name = bprintf("%s#%s", src, dst);
2938 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2939 "Invalid count of links, must be greater than zero (%s,%s)",
2941 xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
2942 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
2943 src, e_route->src_gateway, dst, e_route->dst_gateway);
2945 route_extended_t new_e_route =
2946 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
2947 xbt_dynar_free(&(e_route->generic_route.link_list));
2950 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
2951 (void (*)(void *)) generic_free_extended_route);
2952 xbt_free(route_name);
2955 /* ************************************************************************** */
2956 /* *********************** GENERIC BUSINESS METHODS ************************* */
2958 static double generic_get_link_latency(routing_component_t rc,
2959 const char *src, const char *dst)
2961 route_extended_t route = rc->get_route(rc,src,dst);
2964 double latency = 0.0;
2966 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
2967 latency += get_link_latency(link);
2969 generic_free_extended_route(route);
2973 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
2975 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
2978 static route_extended_t generic_get_bypassroute(routing_component_t rc,
2982 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2983 routing_component_t src_as, dst_as;
2984 int index_src, index_dst;
2985 xbt_dynar_t path_src = NULL;
2986 xbt_dynar_t path_dst = NULL;
2987 routing_component_t current = NULL;
2988 routing_component_t *current_src = NULL;
2989 routing_component_t *current_dst = NULL;
2991 /* (1) find the as where the src and dst are located */
2992 src_as = ((network_element_info_t)
2993 xbt_lib_get_or_null(host_lib, src, ROUTING_HOST_LEVEL))->rc_component;
2994 dst_as = ((network_element_info_t)
2995 xbt_lib_get_or_null(host_lib, dst, ROUTING_HOST_LEVEL))->rc_component;
2998 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
3001 /* (2) find the path to the root routing component */
3002 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
3004 while (current != NULL) {
3005 xbt_dynar_push(path_src, ¤t);
3006 current = current->routing_father;
3008 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
3010 while (current != NULL) {
3011 xbt_dynar_push(path_dst, ¤t);
3012 current = current->routing_father;
3015 /* (3) find the common father */
3016 index_src = path_src->used - 1;
3017 index_dst = path_dst->used - 1;
3018 current_src = xbt_dynar_get_ptr(path_src, index_src);
3019 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
3020 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
3021 routing_component_t *tmp_src, *tmp_dst;
3022 tmp_src = xbt_dynar_pop_ptr(path_src);
3023 tmp_dst = xbt_dynar_pop_ptr(path_dst);
3026 current_src = xbt_dynar_get_ptr(path_src, index_src);
3027 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
3030 int max_index_src = path_src->used - 1;
3031 int max_index_dst = path_dst->used - 1;
3033 int max_index = max(max_index_src, max_index_dst);
3036 route_extended_t e_route_bypass = NULL;
3038 for (max = 0; max <= max_index; max++) {
3039 for (i = 0; i < max; i++) {
3040 if (i <= max_index_src && max <= max_index_dst) {
3041 char *route_name = bprintf("%s#%s",
3042 (*(routing_component_t *)
3044 (path_src, i)))->name,
3045 (*(routing_component_t *)
3047 (path_dst, max)))->name);
3049 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
3050 xbt_free(route_name);
3054 if (max <= max_index_src && i <= max_index_dst) {
3055 char *route_name = bprintf("%s#%s",
3056 (*(routing_component_t *)
3058 (path_src, max)))->name,
3059 (*(routing_component_t *)
3061 (path_dst, i)))->name);
3063 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
3064 xbt_free(route_name);
3073 if (max <= max_index_src && max <= max_index_dst) {
3074 char *route_name = bprintf("%s#%s",
3075 (*(routing_component_t *)
3077 (path_src, max)))->name,
3078 (*(routing_component_t *)
3080 (path_dst, max)))->name);
3081 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
3082 xbt_free(route_name);
3088 xbt_dynar_free(&path_src);
3089 xbt_dynar_free(&path_dst);
3091 route_extended_t new_e_route = NULL;
3093 if (e_route_bypass) {
3095 unsigned int cpt = 0;
3096 new_e_route = xbt_new0(s_route_extended_t, 1);
3097 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
3098 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
3099 new_e_route->generic_route.link_list =
3100 xbt_dynar_new(global_routing->size_of_link, NULL);
3101 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
3102 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
3109 /* ************************************************************************** */
3110 /* ************************* GENERIC AUX FUNCTIONS ************************** */
3113 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
3114 void *data, int order)
3120 xbt_dynar_t links = NULL, links_id = NULL;
3122 new_route = xbt_new0(s_route_t, 1);
3123 new_route->link_list =
3124 xbt_dynar_new(global_routing->size_of_link, NULL);
3126 xbt_assert0(hierarchy == SURF_ROUTING_BASE,
3127 "the hierarchy type is not SURF_ROUTING_BASE");
3129 links = ((route_t) data)->link_list;
3132 links_id = new_route->link_list;
3134 xbt_dynar_foreach(links, cpt, link_name) {
3137 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
3140 xbt_dynar_push(links_id, &link);
3142 xbt_dynar_unshift(links_id, &link);
3144 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3150 static route_extended_t
3151 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
3152 void *data, int order)
3156 route_extended_t e_route, new_e_route;
3159 xbt_dynar_t links = NULL, links_id = NULL;
3161 new_e_route = xbt_new0(s_route_extended_t, 1);
3162 new_e_route->generic_route.link_list =
3163 xbt_dynar_new(global_routing->size_of_link, NULL);
3164 new_e_route->src_gateway = NULL;
3165 new_e_route->dst_gateway = NULL;
3167 xbt_assert0(hierarchy == SURF_ROUTING_BASE
3168 || hierarchy == SURF_ROUTING_RECURSIVE,
3169 "the hierarchy type is not defined");
3171 if (hierarchy == SURF_ROUTING_BASE) {
3173 route = (route_t) data;
3174 links = route->link_list;
3176 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
3178 e_route = (route_extended_t) data;
3179 xbt_assert0(e_route->src_gateway
3180 && e_route->dst_gateway, "bad gateway, is null");
3181 links = e_route->generic_route.link_list;
3183 /* remeber not erase the gateway names */
3184 new_e_route->src_gateway = e_route->src_gateway;
3185 new_e_route->dst_gateway = e_route->dst_gateway;
3188 links_id = new_e_route->generic_route.link_list;
3190 xbt_dynar_foreach(links, cpt, link_name) {
3193 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
3196 xbt_dynar_push(links_id, &link);
3198 xbt_dynar_unshift(links_id, &link);
3200 THROW1(mismatch_error, 0, "Link %s not found", link_name);
3206 static void generic_free_route(route_t route)
3209 xbt_dynar_free(&(route->link_list));
3214 static void generic_free_extended_route(route_extended_t e_route)
3217 xbt_dynar_free(&(e_route->generic_route.link_list));
3218 if (e_route->src_gateway)
3219 xbt_free(e_route->src_gateway);
3220 if (e_route->dst_gateway)
3221 xbt_free(e_route->dst_gateway);
3226 static routing_component_t generic_as_exist(routing_component_t find_from,
3227 routing_component_t to_find)
3229 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3230 xbt_dict_cursor_t cursor = NULL;
3233 routing_component_t elem;
3234 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
3235 if (to_find == elem || generic_as_exist(elem, to_find)) {
3245 static routing_component_t
3246 generic_autonomous_system_exist(routing_component_t rc, char *element)
3248 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3249 routing_component_t element_as, result, elem;
3250 xbt_dict_cursor_t cursor = NULL;
3252 element_as = ((network_element_info_t)
3253 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
3254 result = ((routing_component_t) - 1);
3255 if (element_as != rc)
3256 result = generic_as_exist(rc, element_as);
3260 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
3261 found = !strcmp(elem->name, element);
3271 static routing_component_t
3272 generic_processing_units_exist(routing_component_t rc, char *element)
3274 routing_component_t element_as;
3275 element_as = ((network_element_info_t)
3276 xbt_lib_get_or_null(host_lib,
3277 element, ROUTING_HOST_LEVEL))->rc_component;
3278 if (element_as == rc)
3280 return generic_as_exist(rc, element_as);
3283 static void generic_src_dst_check(routing_component_t rc, const char *src,
3287 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
3288 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
3289 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
3290 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
3292 if(src_data == NULL || dst_data == NULL)
3293 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
3294 src, dst, rc->name);
3296 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
3297 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
3299 if(src_as != dst_as)
3300 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
3301 src, src_as->name, dst, dst_as->name);
3303 xbt_die("The routing component of src and dst is not the same as the network elements belong (%s==%s)",
3304 rc->name, dst_as->name);
3307 static void routing_parse_Sconfig(void)
3309 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
3312 static void routing_parse_Econfig(void)
3314 xbt_dict_cursor_t cursor = NULL;
3318 xbt_dict_foreach(current_property_set, cursor, key, elem) {
3319 cfg = bprintf("%s:%s",key,elem);
3320 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
3321 xbt_cfg_set_parse(_surf_cfg_set, cfg);
3323 XBT_INFO("The custom configuration '%s' is already define by user!",key);
3326 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
3329 static void routing_parse_Scluster(void)
3331 static int AX_ptr = 0;
3333 char *cluster_id = A_surfxml_cluster_id;
3334 char *cluster_prefix = A_surfxml_cluster_prefix;
3335 char *cluster_suffix = A_surfxml_cluster_suffix;
3336 char *cluster_radical = A_surfxml_cluster_radical;
3337 char *cluster_power = A_surfxml_cluster_power;
3338 char *cluster_core = A_surfxml_cluster_core;
3339 char *cluster_bw = A_surfxml_cluster_bw;
3340 char *cluster_lat = A_surfxml_cluster_lat;
3341 char *temp_cluster_bw = NULL;
3342 char *temp_cluster_lat = NULL;
3343 char *temp_cluster_power = NULL;
3344 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
3345 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
3346 char *cluster_availability_file = A_surfxml_cluster_availability_file;
3347 char *cluster_state_file = A_surfxml_cluster_state_file;
3348 char *host_id, *groups, *link_id = NULL;
3349 char *router_id, *link_router, *link_backbone;
3350 char *availability_file = bprintf("%s",cluster_availability_file);
3351 char *state_file = bprintf("%s",cluster_state_file);
3353 if(xbt_dict_size(patterns)==0)
3354 patterns = xbt_dict_new();
3356 xbt_dict_set(patterns,"id",cluster_id,NULL);
3357 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
3358 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
3360 #ifdef HAVE_PCRE_LIB
3361 char *route_src_dst;
3365 xbt_dynar_t radical_elements;
3366 xbt_dynar_t radical_ends;
3367 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
3368 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
3370 #ifndef HAVE_PCRE_LIB
3371 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3372 char *route_src, *route_dst;
3376 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3377 static unsigned int surfxml_buffer_stack_stack[1024];
3379 surfxml_buffer_stack_stack[0] = 0;
3381 surfxml_bufferstack_push(1);
3383 SURFXML_BUFFER_SET(AS_id, cluster_id);
3384 #ifdef HAVE_PCRE_LIB
3385 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3386 SURFXML_BUFFER_SET(AS_coordinates, "");
3387 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
3389 SURFXML_BUFFER_SET(AS_routing, "Full");
3390 SURFXML_BUFFER_SET(AS_coordinates, "");
3391 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
3393 SURFXML_START_TAG(AS);
3395 radical_elements = xbt_str_split(cluster_radical, ",");
3396 xbt_dynar_foreach(radical_elements, iter, groups) {
3397 radical_ends = xbt_str_split(groups, "-");
3398 switch (xbt_dynar_length(radical_ends)) {
3400 surf_parse_get_int(&start,
3401 xbt_dynar_get_as(radical_ends, 0, char *));
3402 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
3403 #ifndef HAVE_PCRE_LIB
3404 xbt_dynar_push_as(tab_elements_num, int, start);
3406 link_id = bprintf("%s_link_%d", cluster_id, start);
3408 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
3409 temp_cluster_power = bprintf("%s",cluster_power);
3410 temp_cluster_power = replace_random_parameter(temp_cluster_power);
3411 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
3412 A_surfxml_host_state = A_surfxml_host_state_ON;
3413 SURFXML_BUFFER_SET(host_id, host_id);
3414 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
3415 SURFXML_BUFFER_SET(host_core, cluster_core);
3416 SURFXML_BUFFER_SET(host_availability, "1.0");
3417 SURFXML_BUFFER_SET(host_coordinates, "");
3418 xbt_free(availability_file);
3419 availability_file = bprintf("%s",cluster_availability_file);
3420 xbt_free(state_file);
3421 state_file = bprintf("%s",cluster_state_file);
3422 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
3423 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
3424 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
3425 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
3426 XBT_DEBUG("</host>");
3427 SURFXML_START_TAG(host);
3428 SURFXML_END_TAG(host);
3431 temp_cluster_bw = bprintf("%s",cluster_bw);
3432 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
3433 temp_cluster_lat = bprintf("%s",cluster_lat);
3434 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
3435 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
3436 A_surfxml_link_state = A_surfxml_link_state_ON;
3437 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3438 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3439 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3440 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3441 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3442 SURFXML_BUFFER_SET(link_id, link_id);
3443 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
3444 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
3445 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3446 SURFXML_BUFFER_SET(link_latency_file, "");
3447 SURFXML_BUFFER_SET(link_state_file, "");
3448 SURFXML_START_TAG(link);
3449 SURFXML_END_TAG(link);
3451 xbt_free(temp_cluster_bw);
3452 xbt_free(temp_cluster_lat);
3453 xbt_free(temp_cluster_power);
3460 surf_parse_get_int(&start,
3461 xbt_dynar_get_as(radical_ends, 0, char *));
3462 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3463 for (i = start; i <= end; i++) {
3464 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
3465 #ifndef HAVE_PCRE_LIB
3466 xbt_dynar_push_as(tab_elements_num, int, i);
3468 link_id = bprintf("%s_link_%d", cluster_id, i);
3470 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
3471 temp_cluster_power = bprintf("%s",cluster_power);
3472 temp_cluster_power = replace_random_parameter(temp_cluster_power);
3473 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
3474 A_surfxml_host_state = A_surfxml_host_state_ON;
3475 SURFXML_BUFFER_SET(host_id, host_id);
3476 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
3477 SURFXML_BUFFER_SET(host_core, cluster_core);
3478 SURFXML_BUFFER_SET(host_availability, "1.0");
3479 SURFXML_BUFFER_SET(host_coordinates, "");
3480 xbt_free(availability_file);
3481 availability_file = bprintf("%s",cluster_availability_file);
3482 xbt_free(state_file);
3483 state_file = bprintf("%s",cluster_state_file);
3484 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
3485 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
3486 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
3487 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
3488 XBT_DEBUG("</host>");
3489 SURFXML_START_TAG(host);
3490 SURFXML_END_TAG(host);
3492 xbt_free(temp_cluster_power);
3494 temp_cluster_bw = bprintf("%s",cluster_bw);
3495 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
3496 temp_cluster_lat = bprintf("%s",cluster_lat);
3497 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
3498 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
3499 A_surfxml_link_state = A_surfxml_link_state_ON;
3500 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3501 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3502 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3503 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3504 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3505 SURFXML_BUFFER_SET(link_id, link_id);
3506 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
3507 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
3508 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3509 SURFXML_BUFFER_SET(link_latency_file, "");
3510 SURFXML_BUFFER_SET(link_state_file, "");
3511 SURFXML_START_TAG(link);
3512 SURFXML_END_TAG(link);
3514 xbt_free(temp_cluster_bw);
3515 xbt_free(temp_cluster_lat);
3522 XBT_DEBUG("Malformed radical");
3525 xbt_dynar_free(&radical_ends);
3527 xbt_dynar_free(&radical_elements);
3531 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
3533 link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
3534 link_backbone = bprintf("%s_backbone", cluster_id);
3536 XBT_DEBUG("<router id=\"%s\"/>", router_id);
3537 SURFXML_BUFFER_SET(router_id, router_id);
3538 SURFXML_BUFFER_SET(router_coordinates, "");
3539 SURFXML_START_TAG(router);
3540 SURFXML_END_TAG(router);
3543 xbt_dict_set(patterns, "radical", bprintf("_router"), xbt_free);
3544 temp_cluster_bw = bprintf("%s",cluster_bw);
3545 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
3546 temp_cluster_lat = bprintf("%s",cluster_lat);
3547 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
3548 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,temp_cluster_bw, temp_cluster_lat);
3549 A_surfxml_link_state = A_surfxml_link_state_ON;
3550 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3551 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3552 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3553 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3554 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3555 SURFXML_BUFFER_SET(link_id, link_router);
3556 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
3557 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
3558 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3559 SURFXML_BUFFER_SET(link_latency_file, "");
3560 SURFXML_BUFFER_SET(link_state_file, "");
3561 SURFXML_START_TAG(link);
3562 SURFXML_END_TAG(link);
3564 xbt_free(temp_cluster_bw);
3565 xbt_free(temp_cluster_lat);
3567 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
3568 A_surfxml_link_state = A_surfxml_link_state_ON;
3569 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3570 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
3571 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
3572 SURFXML_BUFFER_SET(link_id, link_backbone);
3573 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
3574 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
3575 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3576 SURFXML_BUFFER_SET(link_latency_file, "");
3577 SURFXML_BUFFER_SET(link_state_file, "");
3578 SURFXML_START_TAG(link);
3579 SURFXML_END_TAG(link);
3583 #ifdef HAVE_PCRE_LIB
3584 char *new_suffix = xbt_strdup("");
3586 radical_elements = xbt_str_split(cluster_suffix, ".");
3587 xbt_dynar_foreach(radical_elements, iter, groups) {
3588 if (strcmp(groups, "")) {
3589 char *old_suffix = new_suffix;
3590 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
3594 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
3595 xbt_dynar_free(&radical_elements);
3598 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
3599 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
3600 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
3602 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
3603 XBT_DEBUG("symmetrical=\"NO\">");
3604 SURFXML_BUFFER_SET(route_src, route_src_dst);
3605 SURFXML_BUFFER_SET(route_dst, route_src_dst);
3606 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3607 SURFXML_START_TAG(route);
3609 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
3610 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
3611 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3612 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3613 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3614 SURFXML_START_TAG(link_ctn);
3615 SURFXML_END_TAG(link_ctn);
3617 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
3618 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
3619 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3620 SURFXML_START_TAG(link_ctn);
3621 SURFXML_END_TAG(link_ctn);
3623 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
3624 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
3625 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3626 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3627 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3628 SURFXML_START_TAG(link_ctn);
3629 SURFXML_END_TAG(link_ctn);
3631 XBT_DEBUG("</route>");
3632 SURFXML_END_TAG(route);
3634 free(pcre_link_dst);
3635 free(pcre_link_backbone);
3636 free(pcre_link_src);
3637 free(route_src_dst);
3639 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
3640 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
3641 if (i == xbt_dynar_length(tab_elements_num)) {
3642 route_src = router_id;
3645 bprintf("%s%d%s", cluster_prefix,
3646 xbt_dynar_get_as(tab_elements_num, i, int),
3650 if (j == xbt_dynar_length(tab_elements_num)) {
3651 route_dst = router_id;
3654 bprintf("%s%d%s", cluster_prefix,
3655 xbt_dynar_get_as(tab_elements_num, j, int),
3659 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
3660 XBT_DEBUG("symmetrical=\"NO\">");
3661 SURFXML_BUFFER_SET(route_src, route_src);
3662 SURFXML_BUFFER_SET(route_dst, route_dst);
3663 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3664 SURFXML_START_TAG(route);
3666 if (i == xbt_dynar_length(tab_elements_num)) {
3667 route_src = link_router;
3670 bprintf("%s_link_%d", cluster_id,
3671 xbt_dynar_get_as(tab_elements_num, i, int));
3674 if (j == xbt_dynar_length(tab_elements_num)) {
3675 route_dst = link_router;
3678 bprintf("%s_link_%d", cluster_id,
3679 xbt_dynar_get_as(tab_elements_num, j, int));
3682 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_src);
3683 SURFXML_BUFFER_SET(link_ctn_id, route_src);
3684 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3685 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3686 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3687 SURFXML_START_TAG(link_ctn);
3688 SURFXML_END_TAG(link_ctn);
3690 XBT_DEBUG("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3691 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3692 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3693 SURFXML_START_TAG(link_ctn);
3694 SURFXML_END_TAG(link_ctn);
3696 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_dst);
3697 SURFXML_BUFFER_SET(link_ctn_id, route_dst);
3698 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3699 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3700 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3701 SURFXML_START_TAG(link_ctn);
3702 SURFXML_END_TAG(link_ctn);
3704 XBT_DEBUG("</route>");
3705 SURFXML_END_TAG(route);
3708 xbt_dynar_free(&tab_elements_num);
3713 free(link_backbone);
3715 xbt_dict_free(&patterns);
3716 free(availability_file);
3720 SURFXML_END_TAG(AS);
3723 surfxml_bufferstack_pop(1);
3726 * This function take a string and replace parameters from patterns dict.
3727 * It returns the new value.
3729 static char* replace_random_parameter(char * string)
3731 char *test_string = NULL;
3733 if(xbt_dict_size(random_value)==0)
3736 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
3737 test_string = bprintf("${%s}", string);
3738 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
3740 if (strcmp(test_string,"")) { //if not empty, keep this value.
3742 string = test_string;
3743 } //In other case take old value (without ${})
3749 static void clean_dict_random(void)
3751 XBT_DEBUG("Clean dict for random");
3752 xbt_dict_free(&random_value);
3753 xbt_dict_free(&patterns);
3756 static void routing_parse_Speer(void)
3758 static int AX_ptr = 0;
3760 char *peer_id = A_surfxml_peer_id;
3761 char *peer_power = A_surfxml_peer_power;
3762 char *peer_bw_in = A_surfxml_peer_bw_in;
3763 char *peer_bw_out = A_surfxml_peer_bw_out;
3764 char *peer_lat = A_surfxml_peer_lat;
3765 char *peer_coord = A_surfxml_peer_coordinates;
3766 char *peer_state_file = A_surfxml_peer_state_file;
3767 char *peer_availability_file = A_surfxml_peer_availability_file;
3769 char *host_id = NULL;
3770 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
3772 #ifdef HAVE_PCRE_LIB
3776 int peer_sharing_policy = AX_surfxml_peer_sharing_policy;
3778 #ifndef HAVE_PCRE_LIB
3779 //xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3780 //char *route_src, *route_dst;
3784 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3785 static unsigned int surfxml_buffer_stack_stack[1024];
3787 surfxml_buffer_stack_stack[0] = 0;
3789 surfxml_bufferstack_push(1);
3791 SURFXML_BUFFER_SET(AS_id, peer_id);
3792 SURFXML_BUFFER_SET(AS_coordinates, peer_coord);
3793 #ifdef HAVE_PCRE_LIB
3794 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3795 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", peer_id);
3797 SURFXML_BUFFER_SET(AS_routing, "Full");
3798 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
3800 SURFXML_START_TAG(AS);
3803 host_id = bprintf("peer_%s", peer_id);
3804 router_id = bprintf("router_%s", peer_id);
3805 link_id_up = bprintf("link_%s_up", peer_id);
3806 link_id_down = bprintf("link_%s_down", peer_id);
3808 link_router = bprintf("%s_link_router", peer_id);
3809 link_backbone = bprintf("%s_backbone", peer_id);
3811 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
3812 A_surfxml_host_state = A_surfxml_host_state_ON;
3813 SURFXML_BUFFER_SET(host_id, host_id);
3814 SURFXML_BUFFER_SET(host_power, peer_power);
3815 SURFXML_BUFFER_SET(host_availability, "1.0");
3816 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
3817 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
3818 SURFXML_BUFFER_SET(host_coordinates, "");
3819 SURFXML_START_TAG(host);
3820 SURFXML_END_TAG(host);
3822 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
3823 SURFXML_BUFFER_SET(router_id, router_id);
3824 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
3825 SURFXML_START_TAG(router);
3826 SURFXML_END_TAG(router);
3828 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
3829 A_surfxml_link_state = A_surfxml_link_state_ON;
3830 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3831 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3832 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3833 SURFXML_BUFFER_SET(link_id, link_id_up);
3834 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
3835 SURFXML_BUFFER_SET(link_latency, peer_lat);
3836 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3837 SURFXML_BUFFER_SET(link_latency_file, "");
3838 SURFXML_BUFFER_SET(link_state_file, "");
3839 SURFXML_START_TAG(link);
3840 SURFXML_END_TAG(link);
3842 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
3843 A_surfxml_link_state = A_surfxml_link_state_ON;
3844 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3845 if(peer_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3846 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
3847 SURFXML_BUFFER_SET(link_id, link_id_down);
3848 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
3849 SURFXML_BUFFER_SET(link_latency, peer_lat);
3850 SURFXML_BUFFER_SET(link_bandwidth_file, "");
3851 SURFXML_BUFFER_SET(link_latency_file, "");
3852 SURFXML_BUFFER_SET(link_state_file, "");
3853 SURFXML_START_TAG(link);
3854 SURFXML_END_TAG(link);
3859 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", peer_id, router_id);
3860 XBT_DEBUG("symmetrical=\"NO\">");
3861 SURFXML_BUFFER_SET(route_src, peer_id);
3862 SURFXML_BUFFER_SET(route_dst, router_id);
3863 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3864 SURFXML_START_TAG(route);
3866 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
3867 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
3868 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3869 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3870 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3871 SURFXML_START_TAG(link_ctn);
3872 SURFXML_END_TAG(link_ctn);
3874 XBT_DEBUG("</route>");
3875 SURFXML_END_TAG(route);
3878 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, peer_id);
3879 XBT_DEBUG("symmetrical=\"NO\">");
3880 SURFXML_BUFFER_SET(route_src, router_id);
3881 SURFXML_BUFFER_SET(route_dst, peer_id);
3882 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
3883 SURFXML_START_TAG(route);
3885 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
3886 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
3887 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3888 if(peer_sharing_policy == A_surfxml_peer_sharing_policy_FULLDUPLEX)
3889 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3890 SURFXML_START_TAG(link_ctn);
3891 SURFXML_END_TAG(link_ctn);
3893 XBT_DEBUG("</route>");
3894 SURFXML_END_TAG(route);
3897 SURFXML_END_TAG(AS);
3900 //xbt_dynar_free(&tab_elements_num);
3902 surfxml_bufferstack_pop(1);
3905 static void routing_parse_Srandom(void)
3907 double mean, std, min, max, seed;
3908 char *random_id = A_surfxml_random_id;
3909 char *random_radical = A_surfxml_random_radical;
3910 char *rd_name = NULL;
3912 surf_parse_get_double(&mean,A_surfxml_random_mean);
3913 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
3914 surf_parse_get_double(&min,A_surfxml_random_min);
3915 surf_parse_get_double(&max,A_surfxml_random_max);
3916 surf_parse_get_double(&seed,A_surfxml_random_seed);
3920 random_data_t random = xbt_new0(s_random_data_t, 1);
3923 xbt_dynar_t radical_elements;
3927 xbt_dynar_t radical_ends;
3929 random->generator = A_surfxml_random_generator;
3930 random->seed = seed;
3934 /* Check user stupidities */
3936 THROW2(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
3938 THROW2(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
3941 THROW2(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
3944 /* normalize the mean and standard deviation before storing */
3945 random->mean = (mean - min) / (max - min);
3946 random->std = std / (max - min);
3948 if (random->mean * (1 - random->mean) < random->std * random->std)
3949 THROW2(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
3950 random->mean, random->std);
3952 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
3962 if(xbt_dict_size(random_value)==0)
3963 random_value = xbt_dict_new();
3965 if(!strcmp(random_radical,""))
3967 res = random_generate(random);
3968 rd_value = bprintf("%f",res);
3969 xbt_dict_set(random_value, random_id, rd_value, free);
3973 radical_elements = xbt_str_split(random_radical, ",");
3974 xbt_dynar_foreach(radical_elements, iter, groups) {
3975 radical_ends = xbt_str_split(groups, "-");
3976 switch (xbt_dynar_length(radical_ends)) {
3978 xbt_assert1(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
3979 res = random_generate(random);
3980 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
3981 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
3985 case 2: surf_parse_get_int(&start,
3986 xbt_dynar_get_as(radical_ends, 0, char *));
3987 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3988 for (i = start; i <= end; i++) {
3989 xbt_assert1(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
3990 res = random_generate(random);
3991 tmpbuf = bprintf("%s%d",random_id,i);
3992 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
3997 XBT_INFO("Malformed radical");
3999 res = random_generate(random);
4000 rd_name = bprintf("%s_router",random_id);
4001 rd_value = bprintf("%f",res);
4002 xbt_dict_set(random_value, rd_name, rd_value, free);
4004 xbt_dynar_free(&radical_ends);
4007 xbt_dynar_free(&radical_elements);
4011 static void routing_parse_Erandom(void)
4013 xbt_dict_cursor_t cursor = NULL;
4017 xbt_dict_foreach(random_value, cursor, key, elem) {
4018 XBT_DEBUG("%s = %s",key,elem);
4025 * New methods to init the routing model component from the lua script
4029 * calling parse_S_AS_lua with lua values
4031 void routing_AS_init(const char *AS_id, const char *AS_routing)
4033 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
4037 * calling parse_E_AS_lua to fisnish the creation of routing component
4039 void routing_AS_end(const char *AS_id)
4041 parse_E_AS_lua((char *) AS_id);
4045 * add a host to the network element list
4048 void routing_add_host(const char *host_id)
4050 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
4054 * Set a new link on the actual list of link for a route or ASroute
4056 void routing_add_link(const char *link_id)
4058 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
4062 *Set the endpoints for a route
4064 void routing_set_route(const char *src_id, const char *dst_id)
4066 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
4070 * Store the route by calling parse_E_route_store_route
4072 void routing_store_route(void)
4074 parse_E_route_store_route();