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. */
7 #include <pcre.h> /* regular expression library */
8 #include "surf_routing_private.h"
9 #include "surf/surf_routing.h"
10 #include "surf/surfxml_parse_values.h"
13 int ROUTING_HOST_LEVEL; //Routing level
14 int SURF_CPU_LEVEL; //Surf cpu level
15 int SURF_WKS_LEVEL; //Surf workstation level
16 int SIMIX_HOST_LEVEL; //Simix level
17 int MSG_HOST_LEVEL; //Msg level
18 int SD_HOST_LEVEL; //Simdag level
19 int COORD_HOST_LEVEL; //Coordinates level
20 int NS3_HOST_LEVEL; //host node for ns3
23 int SD_LINK_LEVEL; //Simdag level
24 int SURF_LINK_LEVEL; //Surf level
25 int NS3_LINK_LEVEL; //link for ns3
27 xbt_lib_t as_router_lib;
28 int ROUTING_ASR_LEVEL; //Routing level
29 int COORD_ASR_LEVEL; //Coordinates level
30 int NS3_ASR_LEVEL; //host node for ns3
32 static xbt_dict_t patterns = NULL;
33 static xbt_dict_t random_value = NULL;
36 routing_global_t global_routing = NULL;
37 routing_component_t current_routing = NULL;
38 model_type_t current_routing_model = NULL;
40 /* global parse functions */
41 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
42 static const char *src = NULL; /* temporary store the source name of a route */
43 static const char *dst = NULL; /* temporary store the destination name of a route */
44 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
45 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
46 static double_f_cpvoid_t get_link_latency = NULL;
47 xbt_dict_t cluster_host_link = NULL; /* for tag cluster */
49 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
51 static void routing_parse_Speer(void); /* peer bypass */
52 static void routing_parse_Srandom(void); /* random bypass */
53 static void routing_parse_Erandom(void); /* random bypass */
55 static void routing_parse_Sconfig(void); /* config Tag */
56 static void routing_parse_Econfig(void); /* config Tag */
58 static char* replace_random_parameter(char * chaine);
59 static void clean_routing_after_parse(void);
61 /* this lines are only for replace use like index in the model table */
66 SURF_MODEL_DIJKSTRACACHE,
73 struct s_model_type routing_models[] = { {"Full",
74 "Full routing data (fast, large memory requirements, fully expressive)",
80 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
81 model_floyd_create, model_floyd_load, model_floyd_unload,
84 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
85 model_dijkstra_create, model_dijkstra_both_load,
86 model_dijkstra_both_unload, model_dijkstra_both_end},
88 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
89 model_dijkstracache_create, model_dijkstra_both_load,
90 model_dijkstra_both_unload, model_dijkstra_both_end},
91 {"none", "No routing (usable with Constant network only)",
92 model_none_create, model_none_load, model_none_unload, model_none_end},
93 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
94 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
95 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
96 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
97 {"Cluster", "Cluster routing", model_cluster_create,
98 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
99 {NULL, NULL, NULL, NULL, NULL, NULL}
102 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
104 double src_coord, dst_coord;
106 src_coord = atof(xbt_dynar_get_as(src, index, char *));
107 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
109 return (src_coord-dst_coord)*(src_coord-dst_coord);
113 static double base_vivaldi_get_latency (const char *src, const char *dst)
115 double euclidean_dist;
116 xbt_dynar_t src_ctn, dst_ctn;
117 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
118 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
119 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
120 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
122 if(dst_ctn == NULL || src_ctn == NULL)
123 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
125 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
126 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
128 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
131 return euclidean_dist / 1000;
134 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
136 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
137 int need_to_clean = e_route?0:1;
139 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
140 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
141 if(need_to_clean) generic_free_extended_route(e_route);
144 return base_vivaldi_get_latency(src,dst);
149 * \brief Add a "host" to the network element list
151 static void parse_S_host(const char *host_id, const char* coord)
153 network_element_info_t info = NULL;
154 if (current_routing->hierarchy == SURF_ROUTING_NULL)
155 current_routing->hierarchy = SURF_ROUTING_BASE;
156 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
157 "Reading a host, processing unit \"%s\" already exists",
159 xbt_assert(current_routing->set_processing_unit,
160 "no defined method \"set_processing_unit\" in \"%s\"",
161 current_routing->name);
162 (*(current_routing->set_processing_unit)) (current_routing, host_id);
163 info = xbt_new0(s_network_element_info_t, 1);
164 info->rc_component = current_routing;
165 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
166 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
167 if (strcmp(coord,"")) {
168 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
169 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
170 xbt_dynar_shrink(ctn, 0);
171 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
175 static void parse_E_host(void)
177 xbt_dict_cursor_t cursor = NULL;
181 xbt_dict_foreach(current_property_set, cursor, key, elem) {
182 XBT_DEBUG("property : %s = %s",key,elem);
187 * \brief Add a host to the network element list from XML
189 static void parse_S_host_XML(surf_parsing_host_arg_t h)
191 parse_S_host(h->V_host_id, h->V_host_coord);
193 static void parse_E_host_XML(void)
199 * \brief Add a host to the network element list from lua script
201 static void parse_S_host_lua(const char *host_id, const char *coord)
203 parse_S_host(host_id, coord);
208 * \brief Add a "router" to the network element list
210 static void parse_S_router(void)
212 network_element_info_t info = NULL;
213 if (current_routing->hierarchy == SURF_ROUTING_NULL)
214 current_routing->hierarchy = SURF_ROUTING_BASE;
215 xbt_assert(!xbt_lib_get_or_null(as_router_lib,struct_router->V_router_id, ROUTING_ASR_LEVEL),
216 "Reading a router, processing unit \"%s\" already exists",
217 struct_router->V_router_id);
218 xbt_assert(current_routing->set_processing_unit,
219 "no defined method \"set_processing_unit\" in \"%s\"",
220 current_routing->name);
221 (*(current_routing->set_processing_unit)) (current_routing,
222 struct_router->V_router_id);
223 info = xbt_new0(s_network_element_info_t, 1);
224 info->rc_component = current_routing;
225 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
227 xbt_lib_set(as_router_lib,struct_router->V_router_id,ROUTING_ASR_LEVEL,(void *) info);
228 if (strcmp(A_surfxml_router_coordinates,"")) {
229 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
230 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
231 xbt_dynar_shrink(ctn, 0);
232 xbt_lib_set(as_router_lib,struct_router->V_router_id,COORD_ASR_LEVEL,(void *) ctn);
237 * brief Add a "router" to the network element list from XML description
239 static void parse_S_router_XML(void)
241 return parse_S_router();
245 * brief Add a "router" to the network element list from XML description
247 static void parse_S_router_lua(const char* router_id)
249 struct_router->V_router_id = xbt_strdup(router_id);
250 struct_router->V_router_coord = xbt_strdup("");
251 return parse_S_router();
255 * \brief Set the endponints for a route
257 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
259 if (src != NULL && dst != NULL && link_list != NULL)
260 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
264 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
265 "Some limits are null in the route between \"%s\" and \"%s\"",
267 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
271 * \brief Set the endpoints for a route from XML
273 static void parse_S_route_new_and_endpoints_XML(void)
275 parse_S_route_new_and_endpoints(A_surfxml_route_src,
276 A_surfxml_route_dst);
280 * \brief Set the endpoints for a route from lua
282 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
284 parse_S_route_new_and_endpoints(id_src, id_dst);
288 * \brief Set the endponints and gateways for a ASroute
290 static void parse_S_ASroute_new_and_endpoints(void)
292 if (src != NULL && dst != NULL && link_list != NULL)
293 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
294 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
295 src = A_surfxml_ASroute_src;
296 dst = A_surfxml_ASroute_dst;
297 gw_src = A_surfxml_ASroute_gw_src;
298 gw_dst = A_surfxml_ASroute_gw_dst;
299 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
300 || strlen(gw_dst) > 0,
301 "Some limits are null in the route between \"%s\" and \"%s\"",
303 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
307 * \brief Set the endponints for a bypassRoute
309 static void parse_S_bypassRoute_new_and_endpoints(void)
311 if (src != NULL && dst != NULL && link_list != NULL)
313 "Bypass Route between %s to %s can not be defined",
314 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
315 src = A_surfxml_bypassRoute_src;
316 dst = A_surfxml_bypassRoute_dst;
317 gw_src = A_surfxml_bypassRoute_gw_src;
318 gw_dst = A_surfxml_bypassRoute_gw_dst;
319 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
320 || strlen(gw_dst) > 0,
321 "Some limits are null in the route between \"%s\" and \"%s\"",
323 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
327 * \brief Set a new link on the actual list of link for a route or ASroute
329 static void parse_E_link_ctn_new_elem(const char *link_id)
332 val = xbt_strdup(link_id);
333 xbt_dynar_push(link_list, &val);
337 * \brief Set a new link on the actual list of link for a route or ASroute from XML
340 static void parse_E_link_ctn_new_elem_XML(void)
342 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
343 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
344 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
345 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
346 parse_E_link_ctn_new_elem(link_id);
349 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
350 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
351 parse_E_link_ctn_new_elem(link_id);
357 * \brief Set a new link on the actual list of link for a route or ASroute from lua
359 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
361 parse_E_link_ctn_new_elem(link_id);
365 * \brief Store the route by calling the set_route function of the current routing component
367 static void parse_E_route_store_route(void)
369 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
370 route->generic_route.link_list = link_list;
371 xbt_assert(current_routing->set_route,
372 "no defined method \"set_route\" in \"%s\"",
373 current_routing->name);
374 (*(current_routing->set_route)) (current_routing, src, dst, route);
381 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
383 static void parse_E_ASroute_store_route(void)
385 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
386 e_route->generic_route.link_list = link_list;
387 e_route->src_gateway = xbt_strdup(gw_src);
388 e_route->dst_gateway = xbt_strdup(gw_dst);
389 xbt_assert(current_routing->set_ASroute,
390 "no defined method \"set_ASroute\" in \"%s\"",
391 current_routing->name);
392 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
401 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
403 static void parse_E_bypassRoute_store_route(void)
405 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
406 e_route->generic_route.link_list = link_list;
407 e_route->src_gateway = xbt_strdup(gw_src);
408 e_route->dst_gateway = xbt_strdup(gw_dst);
409 xbt_assert(current_routing->set_bypassroute,
410 "no defined method \"set_bypassroute\" in \"%s\"",
411 current_routing->name);
412 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
422 * \brief Make a new routing component
424 * make the new structure and
425 * set the parsing functions to allows parsing the part of the routing tree
427 void routing_AS_init(const char *AS_id, const char *wanted_routing_type)
429 routing_component_t new_routing;
430 model_type_t model = NULL;
432 /* search the routing model */
433 for (cpt = 0; routing_models[cpt].name; cpt++)
434 if (!strcmp(wanted_routing_type, routing_models[cpt].name))
435 model = &routing_models[cpt];
436 /* if its not exist, error */
438 fprintf(stderr, "Routing model %s not found. Existing models:\n",
439 wanted_routing_type);
440 for (cpt = 0; routing_models[cpt].name; cpt++)
441 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
442 routing_models[cpt].desc);
446 /* make a new routing component */
447 new_routing = (routing_component_t) (*(model->create)) ();
448 new_routing->routing = model;
449 new_routing->hierarchy = SURF_ROUTING_NULL;
450 new_routing->name = xbt_strdup(AS_id);
451 new_routing->routing_sons = xbt_dict_new();
453 /* Hack for Vivaldi */
454 if(!strcmp(model->name,"Vivaldi"))
455 new_routing->get_latency = vivaldi_get_link_latency;
457 if (current_routing == NULL && global_routing->root == NULL) {
459 /* it is the first one */
460 new_routing->routing_father = NULL;
461 global_routing->root = new_routing;
463 } else if (current_routing != NULL && global_routing->root != NULL) {
465 xbt_assert(!xbt_dict_get_or_null
466 (current_routing->routing_sons, AS_id),
467 "The AS \"%s\" already exists", AS_id);
468 /* it is a part of the tree */
469 new_routing->routing_father = current_routing;
470 /* set the father behavior */
471 if (current_routing->hierarchy == SURF_ROUTING_NULL)
472 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
473 /* add to the sons dictionary */
474 xbt_dict_set(current_routing->routing_sons, AS_id,
475 (void *) new_routing, NULL);
476 /* add to the father element list */
477 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
478 /* unload the prev parse rules */
479 (*(current_routing->routing->unload)) ();
482 THROWF(arg_error, 0, "All defined components must be belong to a AS");
484 /* set the new parse rules */
485 (*(new_routing->routing->load)) ();
486 /* set the new current component of the tree */
487 current_routing = new_routing;
491 * Detect the routing model type of the routing component from XML platforms
493 static void parse_S_AS(void)
495 routing_AS_init(A_surfxml_AS_id, A_surfxml_AS_routing);
500 * \brief Finish the creation of a new routing component
502 * When you finish to read the routing component, other structures must be created.
503 * the "end" method allow to do that for any routing model type
505 void routing_AS_end(const char *AS_id)
508 if (current_routing == NULL) {
509 THROWF(arg_error, 0, "Close AS(%s), that were never opened", AS_id);
511 network_element_info_t info = NULL;
512 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
513 "The AS \"%s\" already exists",current_routing->name);
514 info = xbt_new0(s_network_element_info_t, 1);
515 info->rc_component = current_routing->routing_father;
516 info->rc_type = SURF_NETWORK_ELEMENT_AS;
517 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
519 (*(current_routing->routing->unload)) ();
520 (*(current_routing->routing->end)) ();
521 current_routing = current_routing->routing_father;
522 if (current_routing != NULL)
523 (*(current_routing->routing->load)) ();
528 * \brief Finish the creation of a new routing component from XML
530 static void parse_E_AS(void)
532 routing_AS_end(A_surfxml_AS_id);
535 /* Aux Business methods */
538 * \brief Get the AS name of the element
540 * \param name the host name
543 static char* elements_As_name(const char *name)
545 routing_component_t as_comp;
547 /* (1) find the as where the host is located */
548 as_comp = ((network_element_info_t)
549 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
550 return as_comp->name;
555 * \brief Get the AS father and the first elements of the chain
557 * \param src the source host name
558 * \param dst the destination host name
560 * Get the common father of the to processing units, and the first different
561 * father in the chain
563 static void elements_father(const char *src, const char *dst,
564 routing_component_t *res_father,
565 routing_component_t *res_src,
566 routing_component_t *res_dst)
568 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
569 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
570 routing_component_t src_as, dst_as;
571 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
572 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
575 routing_component_t current;
576 routing_component_t current_src;
577 routing_component_t current_dst;
578 routing_component_t father;
580 /* (1) find the as where the src and dst are located */
581 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
583 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
586 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
588 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
589 src_as = src_data->rc_component;
590 dst_as = dst_data->rc_component;
592 xbt_assert(src_as && dst_as,
593 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
595 /* (2) find the path to the root routing component */
596 for (current = src_as ; current != NULL ; current = current->routing_father) {
597 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
598 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
599 path_src[index_src++] = current;
601 for (current = dst_as ; current != NULL ; current = current->routing_father) {
602 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
603 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
604 path_dst[index_dst++] = current;
607 /* (3) find the common father */
609 current_src = path_src[--index_src];
610 current_dst = path_dst[--index_dst];
611 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
613 /* (4) they are not in the same routing component, make the path */
614 if (current_src == current_dst)
615 father = current_src;
617 father = path_src[index_src + 1];
619 /* (5) result generation */
620 *res_father = father; /* first the common father of src and dst */
621 *res_src = current_src; /* second the first different father of src */
622 *res_dst = current_dst; /* three the first different father of dst */
624 #undef ELEMENTS_FATHER_MAXDEPTH
627 /* Global Business methods */
630 * \brief Recursive function for get_route_latency
632 * \param src the source host name
633 * \param dst the destination host name
634 * \param *e_route the route where the links are stored
635 * \param *latency the latency, if needed
637 * This function is called by "get_route" and "get_latency". It allows to walk
638 * recursively through the routing components tree.
640 static void _get_route_latency(const char *src, const char *dst,
641 xbt_dynar_t *route, double *latency)
643 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
644 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
646 routing_component_t common_father;
647 routing_component_t src_father;
648 routing_component_t dst_father;
649 elements_father(src, dst, &common_father, &src_father, &dst_father);
651 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
653 route_extended_t e_route = NULL;
655 e_route = common_father->get_route(common_father, src, dst);
656 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
657 *route = e_route->generic_route.link_list;
660 *latency = common_father->get_latency(common_father, src, dst, e_route);
661 xbt_assert(*latency >= 0.0,
662 "latency error on route between \"%s\" and \"%s\"", src, dst);
665 xbt_free(e_route->src_gateway);
666 xbt_free(e_route->dst_gateway);
670 } else { /* SURF_ROUTING_RECURSIVE */
672 route_extended_t e_route_bypass = NULL;
673 if (common_father->get_bypass_route)
674 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
676 xbt_assert(!latency || !e_route_bypass,
677 "Bypass cannot work yet with get_latency");
679 route_extended_t e_route_cnt = e_route_bypass
681 : common_father->get_route(common_father,
682 src_father->name, dst_father->name);
684 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
685 src_father->name, dst_father->name);
687 xbt_assert((e_route_cnt->src_gateway == NULL) ==
688 (e_route_cnt->dst_gateway == NULL),
689 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
692 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
695 *latency = common_father->get_latency(common_father,
696 src_father->name, dst_father->name,
698 xbt_assert(*latency >= 0.0,
699 "latency error on route between \"%s\" and \"%s\"",
700 src_father->name, dst_father->name);
706 if (strcmp(src, e_route_cnt->src_gateway)) {
708 xbt_dynar_t route_src;
710 _get_route_latency(src, e_route_cnt->src_gateway,
711 (route ? &route_src : NULL),
712 (latency ? &latency_src : NULL));
714 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
715 src, e_route_cnt->src_gateway);
716 xbt_dynar_foreach(route_src, cpt, link) {
717 xbt_dynar_push(*route, &link);
719 xbt_dynar_free(&route_src);
722 xbt_assert(latency_src >= 0.0,
723 "latency error on route between \"%s\" and \"%s\"",
724 src, e_route_cnt->src_gateway);
725 *latency += latency_src;
730 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
731 xbt_dynar_push(*route, &link);
735 if (strcmp(e_route_cnt->dst_gateway, dst)) {
737 xbt_dynar_t route_dst;
739 _get_route_latency(e_route_cnt->dst_gateway, dst,
740 (route ? &route_dst : NULL),
741 (latency ? &latency_dst : NULL));
743 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
744 e_route_cnt->dst_gateway, dst);
745 xbt_dynar_foreach(route_dst, cpt, link) {
746 xbt_dynar_push(*route, &link);
748 xbt_dynar_free(&route_dst);
751 xbt_assert(latency_dst >= 0.0,
752 "latency error on route between \"%s\" and \"%s\"",
753 e_route_cnt->dst_gateway, dst);
754 *latency += latency_dst;
758 generic_free_extended_route(e_route_cnt);
763 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
765 static void get_route_latency(const char *src, const char *dst,
766 xbt_dynar_t *route, double *latency, int cleanup)
768 _get_route_latency(src, dst, route, latency);
769 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
770 xbt_assert(!latency || *latency >= 0.0,
771 "latency error on route between \"%s\" and \"%s\"", src, dst);
773 xbt_dynar_free(&global_routing->last_route);
774 global_routing->last_route = cleanup ? *route : NULL;
779 * \brief Generic method: find a route between hosts
781 * \param src the source host name
782 * \param dst the destination host name
784 * walk through the routing components tree and find a route between hosts
785 * by calling the differents "get_route" functions in each routing component.
786 * No need to free the returned dynar. It will be freed at the next call.
788 static xbt_dynar_t get_route(const char *src, const char *dst)
790 xbt_dynar_t route = NULL;
791 get_route_latency(src, dst, &route, NULL, 1);
796 * \brief Generic method: find a route between hosts
798 * \param src the source host name
799 * \param dst the destination host name
801 * same as get_route, but return NULL if any exception is raised.
803 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
805 xbt_dynar_t route = NULL;
808 get_route_latency(src, dst, &route, NULL, 1);
810 xbt_ex_free(exception);
817 * \brief Generic method: find a route between hosts
819 * \param src the source host name
820 * \param dst the destination host name
822 * walk through the routing components tree and find a route between hosts
823 * by calling the differents "get_route" functions in each routing component.
824 * Leaves the caller the responsability to clean the returned dynar.
826 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
828 xbt_dynar_t route = NULL;
829 get_route_latency(src, dst, &route, NULL, 0);
834 static double get_latency(const char *src, const char *dst)
836 double latency = -1.0;
837 get_route_latency(src, dst, NULL, &latency, 0);
841 static int surf_parse_models_setup_already_called=0;
842 /* Call the last initialization functions, that must be called after the
843 * <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
845 void surf_parse_models_setup()
847 if (surf_parse_models_setup_already_called)
849 surf_parse_models_setup_already_called=1;
850 routing_parse_Erandom();
851 surf_config_models_setup();
856 * \brief Recursive function for finalize
858 * \param rc the source host name
860 * This fuction is call by "finalize". It allow to finalize the
861 * AS or routing components. It delete all the structures.
863 static void _finalize(routing_component_t rc)
866 xbt_dict_cursor_t cursor = NULL;
868 routing_component_t elem;
869 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
872 xbt_dict_t tmp_sons = rc->routing_sons;
873 char *tmp_name = rc->name;
874 xbt_dict_free(&tmp_sons);
876 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
877 current_routing->name);
878 (*(rc->finalize)) (rc);
883 * \brief Generic method: delete all the routing structures
885 * walk through the routing components tree and delete the structures
886 * by calling the differents "finalize" functions in each routing component
888 static void finalize(void)
890 /* delete recursibly all the tree */
891 _finalize(global_routing->root);
892 /* delete last_route */
893 xbt_dynar_free(&(global_routing->last_route));
894 /* delete global routing structure */
895 xbt_free(global_routing);
896 /* make sure that we will reinit the models while loading the platf once reinited -- HACK but there is no proper surf_routing_init() */
897 surf_parse_models_setup_already_called = 0;
900 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
902 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
904 //adding my one link routes
907 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
909 xbt_dynar_foreach(onelink_mine, cpt, link) {
910 xbt_dynar_push(ret, &link);
915 xbt_dict_cursor_t cursor = NULL;
916 routing_component_t rc_child;
917 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
918 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
920 xbt_dynar_foreach(onelink_child, cpt, link) {
921 xbt_dynar_push(ret, &link);
928 static xbt_dynar_t get_onelink_routes(void)
930 return recursive_get_onelink_routes(global_routing->root);
933 e_surf_network_element_type_t get_network_element_type(const char
936 network_element_info_t rc = NULL;
938 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
939 if(rc) return rc->rc_type;
941 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
942 if(rc) return rc->rc_type;
944 return SURF_NETWORK_ELEMENT_NULL;
948 * \brief Generic method: create the global routing schema
950 * Make a global routing structure and set all the parsing functions.
952 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
954 /* config the uniq global routing */
955 global_routing = xbt_new0(s_routing_global_t, 1);
956 global_routing->root = NULL;
957 global_routing->get_route = get_route;
958 global_routing->get_route_or_null = get_route_or_null;
959 global_routing->get_latency = get_latency;
960 global_routing->get_route_no_cleanup = get_route_no_cleanup;
961 global_routing->get_onelink_routes = get_onelink_routes;
962 global_routing->get_route_latency = get_route_latency;
963 global_routing->get_network_element_type = get_network_element_type;
964 global_routing->finalize = finalize;
965 global_routing->loopback = loopback;
966 global_routing->size_of_link = size_of_links;
967 global_routing->last_route = NULL;
968 get_link_latency = get_link_latency_fun;
969 /* no current routing at moment */
970 current_routing = NULL;
972 /* parse generic elements */
973 surf_parse_host_add_cb(parse_S_host_XML);
974 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
975 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
977 surfxml_add_callback(STag_surfxml_route_cb_list,
978 &parse_S_route_new_and_endpoints_XML);
979 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
980 &parse_S_ASroute_new_and_endpoints);
981 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
982 &parse_S_bypassRoute_new_and_endpoints);
984 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
985 &parse_E_link_ctn_new_elem_XML);
987 surfxml_add_callback(ETag_surfxml_route_cb_list,
988 &parse_E_route_store_route);
989 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
990 &parse_E_ASroute_store_route);
991 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
992 &parse_E_bypassRoute_store_route);
994 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS);
995 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS);
997 surfxml_add_callback(STag_surfxml_cluster_cb_list,
998 &routing_parse_Scluster);
1000 surfxml_add_callback(STag_surfxml_peer_cb_list,
1001 &routing_parse_Speer);
1003 surfxml_add_callback(ETag_surfxml_platform_cb_list,
1004 &clean_routing_after_parse);
1007 instr_routing_define_callbacks();
1011 void surf_parse_add_callback_config(void)
1013 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1014 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1015 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1016 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1019 /* ************************************************** */
1020 /* ********** PATERN FOR NEW ROUTING **************** */
1022 /* The minimal configuration of a new routing model need the next functions,
1023 * also you need to set at the start of the file, the new model in the model
1024 * list. Remember keep the null ending of the list.
1026 /*** Routing model structure ***/
1028 // s_routing_component_t generic_routing;
1029 // /* things that your routing model need */
1030 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1032 /*** Parse routing model functions ***/
1033 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1034 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1035 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1036 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1037 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1039 /*** Business methods ***/
1040 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1041 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1042 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1044 /*** Creation routing model functions ***/
1045 // static void* model_NEW_create(void) {
1046 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1047 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1048 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1049 // new_component->generic_routing.set_route = model_NEW_set_route;
1050 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1051 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1052 // new_component->generic_routing.get_route = NEW_get_route;
1053 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1054 // new_component->generic_routing.finalize = NEW_finalize;
1055 // /* initialization of internal structures */
1056 // return new_component;
1057 // } /* mandatory */
1058 // static void model_NEW_load(void) {} /* mandatory */
1059 // static void model_NEW_unload(void) {} /* mandatory */
1060 // static void model_NEW_end(void) {} /* mandatory */
1062 /* ************************************************************************** */
1063 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1065 void generic_set_processing_unit(routing_component_t rc,
1068 XBT_DEBUG("Load process unit \"%s\"", name);
1069 int *id = xbt_new0(int, 1);
1070 xbt_dict_t _to_index;
1071 _to_index = current_routing->to_index;
1072 *id = xbt_dict_length(_to_index);
1073 xbt_dict_set(_to_index, name, id, xbt_free);
1076 void generic_set_autonomous_system(routing_component_t rc,
1079 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1080 int *id = xbt_new0(int, 1);
1081 xbt_dict_t _to_index;
1082 _to_index = current_routing->to_index;
1083 *id = xbt_dict_length(_to_index);
1084 xbt_dict_set(_to_index, name, id, xbt_free);
1087 int surf_pointer_resource_cmp(const void *a, const void *b)
1092 int surf_link_resource_cmp(const void *a, const void *b)
1094 return !!memcmp(a,b,global_routing->size_of_link);
1097 void generic_set_bypassroute(routing_component_t rc,
1098 const char *src, const char *dst,
1099 route_extended_t e_route)
1101 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1102 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1105 route_name = bprintf("%s#%s", src, dst);
1106 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1107 "Invalid count of links, must be greater than zero (%s,%s)",
1109 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1110 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1111 src, e_route->src_gateway, dst, e_route->dst_gateway);
1113 route_extended_t new_e_route =
1114 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1115 xbt_dynar_free(&(e_route->generic_route.link_list));
1118 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1119 (void (*)(void *)) generic_free_extended_route);
1120 xbt_free(route_name);
1123 /* ************************************************************************** */
1124 /* *********************** GENERIC BUSINESS METHODS ************************* */
1126 double generic_get_link_latency(routing_component_t rc,
1127 const char *src, const char *dst,
1128 route_extended_t route)
1130 int need_to_clean = route?0:1;
1133 double latency = 0.0;
1135 route = route?route:rc->get_route(rc,src,dst);
1137 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1138 latency += get_link_latency(link);
1140 if(need_to_clean) generic_free_extended_route(route);
1144 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1146 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1149 route_extended_t generic_get_bypassroute(routing_component_t rc,
1153 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1154 routing_component_t src_as, dst_as;
1155 int index_src, index_dst;
1156 xbt_dynar_t path_src = NULL;
1157 xbt_dynar_t path_dst = NULL;
1158 routing_component_t current = NULL;
1159 routing_component_t *current_src = NULL;
1160 routing_component_t *current_dst = NULL;
1162 /* (1) find the as where the src and dst are located */
1163 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1164 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1165 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1166 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1168 if(src_data == NULL || dst_data == NULL)
1169 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1170 src, dst, rc->name);
1172 src_as = ((network_element_info_t)src_data)->rc_component;
1173 dst_as = ((network_element_info_t)dst_data)->rc_component;
1175 /* (2) find the path to the root routing component */
1176 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1178 while (current != NULL) {
1179 xbt_dynar_push(path_src, ¤t);
1180 current = current->routing_father;
1182 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1184 while (current != NULL) {
1185 xbt_dynar_push(path_dst, ¤t);
1186 current = current->routing_father;
1189 /* (3) find the common father */
1190 index_src = path_src->used - 1;
1191 index_dst = path_dst->used - 1;
1192 current_src = xbt_dynar_get_ptr(path_src, index_src);
1193 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1194 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1195 xbt_dynar_pop_ptr(path_src);
1196 xbt_dynar_pop_ptr(path_dst);
1199 current_src = xbt_dynar_get_ptr(path_src, index_src);
1200 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1203 int max_index_src = path_src->used - 1;
1204 int max_index_dst = path_dst->used - 1;
1206 int max_index = max(max_index_src, max_index_dst);
1209 route_extended_t e_route_bypass = NULL;
1211 for (max = 0; max <= max_index; max++) {
1212 for (i = 0; i < max; i++) {
1213 if (i <= max_index_src && max <= max_index_dst) {
1214 char *route_name = bprintf("%s#%s",
1215 (*(routing_component_t *)
1217 (path_src, i)))->name,
1218 (*(routing_component_t *)
1220 (path_dst, max)))->name);
1222 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1223 xbt_free(route_name);
1227 if (max <= max_index_src && i <= max_index_dst) {
1228 char *route_name = bprintf("%s#%s",
1229 (*(routing_component_t *)
1231 (path_src, max)))->name,
1232 (*(routing_component_t *)
1234 (path_dst, i)))->name);
1236 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1237 xbt_free(route_name);
1246 if (max <= max_index_src && max <= max_index_dst) {
1247 char *route_name = bprintf("%s#%s",
1248 (*(routing_component_t *)
1250 (path_src, max)))->name,
1251 (*(routing_component_t *)
1253 (path_dst, max)))->name);
1254 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1255 xbt_free(route_name);
1261 xbt_dynar_free(&path_src);
1262 xbt_dynar_free(&path_dst);
1264 route_extended_t new_e_route = NULL;
1266 if (e_route_bypass) {
1268 unsigned int cpt = 0;
1269 new_e_route = xbt_new0(s_route_extended_t, 1);
1270 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1271 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1272 new_e_route->generic_route.link_list =
1273 xbt_dynar_new(global_routing->size_of_link, NULL);
1274 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1275 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1282 /* ************************************************************************** */
1283 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1286 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1287 void *data, int order)
1293 xbt_dynar_t links = NULL, links_id = NULL;
1295 new_route = xbt_new0(s_route_t, 1);
1296 new_route->link_list =
1297 xbt_dynar_new(global_routing->size_of_link, NULL);
1299 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1300 "the hierarchy type is not SURF_ROUTING_BASE");
1302 links = ((route_t) data)->link_list;
1305 links_id = new_route->link_list;
1307 xbt_dynar_foreach(links, cpt, link_name) {
1310 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1313 xbt_dynar_push(links_id, &link);
1315 xbt_dynar_unshift(links_id, &link);
1317 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1324 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1325 void *data, int order)
1329 route_extended_t e_route, new_e_route;
1332 xbt_dynar_t links = NULL, links_id = NULL;
1334 new_e_route = xbt_new0(s_route_extended_t, 1);
1335 new_e_route->generic_route.link_list =
1336 xbt_dynar_new(global_routing->size_of_link, NULL);
1337 new_e_route->src_gateway = NULL;
1338 new_e_route->dst_gateway = NULL;
1340 xbt_assert(hierarchy == SURF_ROUTING_BASE
1341 || hierarchy == SURF_ROUTING_RECURSIVE,
1342 "the hierarchy type is not defined");
1344 if (hierarchy == SURF_ROUTING_BASE) {
1346 route = (route_t) data;
1347 links = route->link_list;
1349 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1351 e_route = (route_extended_t) data;
1352 xbt_assert(e_route->src_gateway
1353 && e_route->dst_gateway, "bad gateway, is null");
1354 links = e_route->generic_route.link_list;
1356 /* remeber not erase the gateway names */
1357 new_e_route->src_gateway = strdup(e_route->src_gateway);
1358 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1361 links_id = new_e_route->generic_route.link_list;
1363 xbt_dynar_foreach(links, cpt, link_name) {
1366 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1369 xbt_dynar_push(links_id, &link);
1371 xbt_dynar_unshift(links_id, &link);
1373 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1379 void generic_free_route(route_t route)
1382 xbt_dynar_free(&(route->link_list));
1387 void generic_free_extended_route(route_extended_t e_route)
1390 xbt_dynar_free(&(e_route->generic_route.link_list));
1391 if (e_route->src_gateway)
1392 xbt_free(e_route->src_gateway);
1393 if (e_route->dst_gateway)
1394 xbt_free(e_route->dst_gateway);
1399 static routing_component_t generic_as_exist(routing_component_t find_from,
1400 routing_component_t to_find)
1402 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1403 xbt_dict_cursor_t cursor = NULL;
1406 routing_component_t elem;
1407 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1408 if (to_find == elem || generic_as_exist(elem, to_find)) {
1419 generic_autonomous_system_exist(routing_component_t rc, char *element)
1421 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1422 routing_component_t element_as, result, elem;
1423 xbt_dict_cursor_t cursor = NULL;
1425 element_as = ((network_element_info_t)
1426 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1427 result = ((routing_component_t) - 1);
1428 if (element_as != rc)
1429 result = generic_as_exist(rc, element_as);
1433 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1434 found = !strcmp(elem->name, element);
1445 generic_processing_units_exist(routing_component_t rc, char *element)
1447 routing_component_t element_as;
1448 element_as = ((network_element_info_t)
1449 xbt_lib_get_or_null(host_lib,
1450 element, ROUTING_HOST_LEVEL))->rc_component;
1451 if (element_as == rc)
1453 return generic_as_exist(rc, element_as);
1456 void generic_src_dst_check(routing_component_t rc, const char *src,
1460 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1461 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1462 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1463 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1465 if(src_data == NULL || dst_data == NULL)
1466 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1467 src, dst, rc->name);
1469 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1470 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1472 if(src_as != dst_as)
1473 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1474 src, src_as->name, dst, dst_as->name);
1476 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1477 src,dst,src_as->name, dst_as->name,rc->name);
1480 static void routing_parse_Sconfig(void)
1482 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1485 static void routing_parse_Econfig(void)
1487 xbt_dict_cursor_t cursor = NULL;
1491 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1492 cfg = bprintf("%s:%s",key,elem);
1493 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1494 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1496 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
1499 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1502 static void parse_create_host_link(int i)
1504 char *host_id, *link_id = NULL;
1505 s_surf_parsing_host_arg_t host;
1506 memset(&host,0,sizeof(host));
1508 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1509 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1511 A_surfxml_host_state = A_surfxml_host_state_ON;
1513 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1514 host.V_host_id = xbt_strdup(host_id);
1515 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1516 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1517 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1518 xbt_str_varsubst(tmp_availability_file,patterns);
1519 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1520 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1521 xbt_free(tmp_availability_file);
1525 XBT_DEBUG("\tavailability_file=\"\"");
1527 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1528 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1529 xbt_str_varsubst(tmp_state_file,patterns);
1530 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1531 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1532 xbt_free(tmp_state_file);
1536 XBT_DEBUG("\tstate_file=\"\"");
1539 host.V_host_power_peak = struct_cluster->S_cluster_power;
1540 host.V_host_power_scale = 1.0;
1541 host.V_host_core = struct_cluster->S_cluster_core;
1542 host.V_host_state_initial = SURF_RESOURCE_ON;
1543 host.V_host_coord = "";
1544 surf_parse_host(&host);
1545 XBT_DEBUG("</host>");
1547 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1548 if(AX_surfxml_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1549 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1550 if(AX_surfxml_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1551 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1553 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1555 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1556 struct_lnk->V_link_id = xbt_strdup(link_id);
1557 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1558 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1559 struct_lnk->V_link_bandwidth_file = NULL;
1560 struct_lnk->V_link_latency_file = NULL;
1561 struct_lnk->V_link_state_file = NULL;
1562 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1563 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1565 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1566 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1569 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1570 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1571 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1572 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1576 ETag_surfxml_host();
1577 ETag_surfxml_link();
1579 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1581 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX){
1582 char* tmp_link = bprintf("%s_UP",link_id);
1583 info->link_up = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1585 tmp_link = bprintf("%s_DOWN",link_id);
1586 info->link_down = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1590 info->link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
1591 info->link_down = info->link_up;
1593 xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
1598 void routing_parse_Scluster(void)
1600 if(!cluster_host_link)
1601 cluster_host_link = xbt_dict_new();
1603 static int AX_ptr = 0;
1604 char *host_id, *groups, *link_id = NULL;
1606 s_surf_parsing_host_arg_t host;
1608 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1609 || strcmp(struct_cluster->V_cluster_state_file,"") )
1611 if(xbt_dict_size(patterns)==0)
1612 patterns = xbt_dict_new();
1613 xbt_dict_set(patterns,"id",struct_cluster->V_cluster_id,NULL);
1614 xbt_dict_set(patterns,"prefix",struct_cluster->V_cluster_prefix,NULL);
1615 xbt_dict_set(patterns,"suffix",struct_cluster->V_cluster_suffix,NULL);
1620 xbt_dynar_t radical_elements;
1621 xbt_dynar_t radical_ends;
1623 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1624 static unsigned int surfxml_buffer_stack_stack[1024];
1626 surfxml_buffer_stack_stack[0] = 0;
1627 surfxml_bufferstack_push(1);
1629 SURFXML_BUFFER_SET(AS_id, struct_cluster->V_cluster_id);
1630 SURFXML_BUFFER_SET(AS_routing, "Cluster");
1631 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", struct_cluster->V_cluster_id);
1632 SURFXML_START_TAG(AS);
1635 radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ",");
1636 xbt_dynar_foreach(radical_elements, iter, groups) {
1637 memset(&host,0,sizeof(host));
1639 radical_ends = xbt_str_split(groups, "-");
1640 switch (xbt_dynar_length(radical_ends)) {
1642 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
1643 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, start, struct_cluster->V_cluster_suffix);
1644 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start);
1646 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1647 host.V_host_id = host_id;
1648 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1649 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1650 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1651 xbt_str_varsubst(tmp_availability_file,patterns);
1652 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1653 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1654 xbt_free(tmp_availability_file);
1658 XBT_DEBUG("\tavailability_file=\"\"");
1660 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1661 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1662 xbt_str_varsubst(tmp_state_file,patterns);
1663 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1664 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1665 xbt_free(tmp_state_file);
1669 XBT_DEBUG("\tstate_file=\"\"");
1672 host.V_host_power_peak = struct_cluster->S_cluster_power;
1673 host.V_host_power_scale = 1.0;
1674 host.V_host_core = struct_cluster->S_cluster_core;
1675 host.V_host_state_initial = SURF_RESOURCE_ON;
1676 host.V_host_coord = "";
1677 surf_parse_host(&host);
1678 XBT_DEBUG("</host>");
1680 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1681 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1682 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1683 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1684 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1686 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1688 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1689 struct_lnk->V_link_id = link_id;
1690 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1691 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1692 struct_lnk->V_link_bandwidth_file = NULL;
1693 struct_lnk->V_link_latency_file = NULL;
1694 struct_lnk->V_link_state_file = NULL;
1695 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1696 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1698 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1699 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1702 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1703 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1704 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1705 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1709 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1710 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1711 ETag_surfxml_host();
1712 ETag_surfxml_link();
1718 surf_parse_get_int(&start,
1719 xbt_dynar_get_as(radical_ends, 0, char *));
1720 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1721 for (i = start; i <= end; i++) {
1722 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1723 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1725 A_surfxml_host_state = A_surfxml_host_state_ON;
1727 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1728 host.V_host_id = host_id;
1729 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1730 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1731 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1732 xbt_str_varsubst(tmp_availability_file,patterns);
1733 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1734 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1735 xbt_free(tmp_availability_file);
1739 XBT_DEBUG("\tavailability_file=\"\"");
1741 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1742 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1743 xbt_str_varsubst(tmp_state_file,patterns);
1744 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1745 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1746 xbt_free(tmp_state_file);
1750 XBT_DEBUG("\tstate_file=\"\"");
1753 host.V_host_power_peak = struct_cluster->S_cluster_power;
1754 host.V_host_power_scale = 1.0;
1755 host.V_host_core = struct_cluster->S_cluster_core;
1756 host.V_host_state_initial = SURF_RESOURCE_ON;
1757 host.V_host_coord = "";
1758 surf_parse_host(&host);
1759 XBT_DEBUG("</host>");
1761 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1762 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1763 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1764 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1765 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1767 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1769 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1770 struct_lnk->V_link_id = link_id;
1771 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1772 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1773 struct_lnk->V_link_bandwidth_file = NULL;
1774 struct_lnk->V_link_latency_file = NULL;
1775 struct_lnk->V_link_state_file = NULL;
1776 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1777 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1779 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1780 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1783 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1784 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1785 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1786 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1790 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1791 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1793 ETag_surfxml_host();
1794 ETag_surfxml_link();
1800 XBT_DEBUG("Malformed radical");
1804 xbt_dynar_free(&radical_ends);
1806 xbt_dynar_free(&radical_elements);
1810 XBT_DEBUG("<router id=\"%s\"/>", struct_cluster->S_cluster_router_id);
1811 SURFXML_BUFFER_SET(router_id, struct_cluster->S_cluster_router_id);
1812 SURFXML_BUFFER_SET(router_coordinates, "");
1813 SURFXML_START_TAG(router);
1814 SURFXML_END_TAG(router);
1817 if( (struct_cluster->S_cluster_bb_bw!= 0) && (struct_cluster->S_cluster_bb_lat!=0) ){
1818 char *link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1819 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,struct_cluster->S_cluster_bb_bw, struct_cluster->S_cluster_bb_lat);
1821 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1822 if(AX_surfxml_cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1823 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1825 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1826 struct_lnk->V_link_id = xbt_strdup(link_backbone);
1827 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bb_bw;
1828 struct_lnk->V_link_latency = struct_cluster->S_cluster_bb_lat;
1829 struct_lnk->V_link_bandwidth_file = NULL;
1830 struct_lnk->V_link_latency_file = NULL;
1831 struct_lnk->V_link_state_file = NULL;
1832 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1833 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1835 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1836 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1838 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1841 ETag_surfxml_link();
1843 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1844 info->link_up = xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL);
1845 info->link_down = info->link_up;
1846 xbt_dict_set(cluster_host_link,struct_cluster->V_cluster_id,info,xbt_free);
1847 free(link_backbone);
1852 char *new_suffix = xbt_strdup("");
1854 radical_elements = xbt_str_split(struct_cluster->V_cluster_suffix, ".");
1855 xbt_dynar_foreach(radical_elements, iter, groups) {
1856 if (strcmp(groups, "")) {
1857 char *old_suffix = new_suffix;
1858 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1863 xbt_dynar_free(&radical_elements);
1864 xbt_free(new_suffix);
1866 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1867 || strcmp(struct_cluster->V_cluster_state_file,"") )
1868 xbt_dict_free(&patterns);
1871 SURFXML_END_TAG(AS);
1874 surfxml_bufferstack_pop(1);
1877 * This function take a string and replace parameters from patterns dict.
1878 * It returns the new value.
1880 static char* replace_random_parameter(char * string)
1882 char *test_string = NULL;
1884 if(xbt_dict_size(random_value)==0)
1887 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1888 test_string = bprintf("${%s}", string);
1889 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1891 if (strcmp(test_string,"")) { //if not empty, keep this value.
1893 string = test_string;
1894 } //In other case take old value (without ${})
1900 static void clean_routing_after_parse(void)
1902 xbt_dict_free(&random_value);
1903 xbt_dict_free(&patterns);
1906 static void routing_parse_Speer(void)
1908 static int AX_ptr = 0;
1909 char *host_id = NULL;
1910 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1912 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1913 static unsigned int surfxml_buffer_stack_stack[1024];
1915 surfxml_buffer_stack_stack[0] = 0;
1917 surfxml_bufferstack_push(1);
1919 SURFXML_BUFFER_SET(AS_id, struct_peer->V_peer_id);
1921 SURFXML_BUFFER_SET(AS_routing, "Full");
1922 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->V_peer_id);
1924 SURFXML_START_TAG(AS);
1927 host_id = bprintf("peer_%s", struct_peer->V_peer_id);
1928 router_id = bprintf("router_%s", struct_peer->V_peer_id);
1929 link_id_up = bprintf("link_%s_up", struct_peer->V_peer_id);
1930 link_id_down = bprintf("link_%s_down", struct_peer->V_peer_id);
1932 link_router = bprintf("%s_link_router", struct_peer->V_peer_id);
1933 link_backbone = bprintf("%s_backbone", struct_peer->V_peer_id);
1935 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, struct_peer->V_peer_power);
1936 A_surfxml_host_state = A_surfxml_host_state_ON;
1937 SURFXML_BUFFER_SET(host_id, host_id);
1938 SURFXML_BUFFER_SET(host_power, struct_peer->V_peer_power);
1939 SURFXML_BUFFER_SET(host_availability, "1.0");
1940 SURFXML_BUFFER_SET(host_availability_file, struct_peer->V_peer_availability_trace);
1941 SURFXML_BUFFER_SET(host_state_file, struct_peer->V_peer_state_trace);
1942 SURFXML_BUFFER_SET(host_coordinates, "");
1943 SURFXML_BUFFER_SET(host_core, "1.0");
1944 SURFXML_START_TAG(host);
1945 SURFXML_END_TAG(host);
1947 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->V_peer_coord);
1948 SURFXML_BUFFER_SET(router_id, router_id);
1949 SURFXML_BUFFER_SET(router_coordinates, struct_peer->V_peer_coord);
1950 SURFXML_START_TAG(router);
1951 SURFXML_END_TAG(router);
1953 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, struct_peer->V_peer_bw_in, struct_peer->V_peer_lat);
1954 A_surfxml_link_state = A_surfxml_link_state_ON;
1955 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1956 SURFXML_BUFFER_SET(link_id, link_id_up);
1957 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_in);
1958 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1959 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1960 SURFXML_BUFFER_SET(link_latency_file, "");
1961 SURFXML_BUFFER_SET(link_state_file, "");
1962 SURFXML_START_TAG(link);
1963 SURFXML_END_TAG(link);
1965 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, struct_peer->V_peer_bw_out, struct_peer->V_peer_lat);
1966 A_surfxml_link_state = A_surfxml_link_state_ON;
1967 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1968 SURFXML_BUFFER_SET(link_id, link_id_down);
1969 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_out);
1970 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1971 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1972 SURFXML_BUFFER_SET(link_latency_file, "");
1973 SURFXML_BUFFER_SET(link_state_file, "");
1974 SURFXML_START_TAG(link);
1975 SURFXML_END_TAG(link);
1980 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1981 XBT_DEBUG("symmetrical=\"NO\">");
1982 SURFXML_BUFFER_SET(route_src, host_id);
1983 SURFXML_BUFFER_SET(route_dst, router_id);
1984 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1985 SURFXML_START_TAG(route);
1987 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1988 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1989 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1990 SURFXML_START_TAG(link_ctn);
1991 SURFXML_END_TAG(link_ctn);
1993 XBT_DEBUG("</route>");
1994 SURFXML_END_TAG(route);
1997 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1998 XBT_DEBUG("symmetrical=\"NO\">");
1999 SURFXML_BUFFER_SET(route_src, router_id);
2000 SURFXML_BUFFER_SET(route_dst, host_id);
2001 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2002 SURFXML_START_TAG(route);
2004 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
2005 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
2006 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2007 SURFXML_START_TAG(link_ctn);
2008 SURFXML_END_TAG(link_ctn);
2010 XBT_DEBUG("</route>");
2011 SURFXML_END_TAG(route);
2014 SURFXML_END_TAG(AS);
2017 //xbt_dynar_free(&tab_elements_num);
2021 free(link_backbone);
2024 surfxml_bufferstack_pop(1);
2027 static void routing_parse_Srandom(void)
2029 double mean, std, min, max, seed;
2030 char *random_id = A_surfxml_random_id;
2031 char *random_radical = A_surfxml_random_radical;
2032 char *rd_name = NULL;
2034 surf_parse_get_double(&mean,A_surfxml_random_mean);
2035 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2036 surf_parse_get_double(&min,A_surfxml_random_min);
2037 surf_parse_get_double(&max,A_surfxml_random_max);
2038 surf_parse_get_double(&seed,A_surfxml_random_seed);
2042 random_data_t random = xbt_new0(s_random_data_t, 1);
2045 xbt_dynar_t radical_elements;
2049 xbt_dynar_t radical_ends;
2051 random->generator = A_surfxml_random_generator;
2052 random->seed = seed;
2056 /* Check user stupidities */
2058 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2060 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2063 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2066 /* normalize the mean and standard deviation before storing */
2067 random->mean = (mean - min) / (max - min);
2068 random->std = std / (max - min);
2070 if (random->mean * (1 - random->mean) < random->std * random->std)
2071 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2072 random->mean, random->std);
2074 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2084 if(xbt_dict_size(random_value)==0)
2085 random_value = xbt_dict_new();
2087 if(!strcmp(random_radical,""))
2089 res = random_generate(random);
2090 rd_value = bprintf("%f",res);
2091 xbt_dict_set(random_value, random_id, rd_value, free);
2095 radical_elements = xbt_str_split(random_radical, ",");
2096 xbt_dynar_foreach(radical_elements, iter, groups) {
2097 radical_ends = xbt_str_split(groups, "-");
2098 switch (xbt_dynar_length(radical_ends)) {
2100 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2101 res = random_generate(random);
2102 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2103 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2107 case 2: surf_parse_get_int(&start,
2108 xbt_dynar_get_as(radical_ends, 0, char *));
2109 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2110 for (i = start; i <= end; i++) {
2111 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2112 res = random_generate(random);
2113 tmpbuf = bprintf("%s%d",random_id,i);
2114 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2119 XBT_INFO("Malformed radical");
2122 res = random_generate(random);
2123 rd_name = bprintf("%s_router",random_id);
2124 rd_value = bprintf("%f",res);
2125 xbt_dict_set(random_value, rd_name, rd_value, free);
2127 xbt_dynar_free(&radical_ends);
2130 xbt_dynar_free(&radical_elements);
2134 static void routing_parse_Erandom(void)
2136 /*xbt_dict_cursor_t cursor = NULL;
2140 xbt_dict_foreach(random_value, cursor, key, elem) {
2141 XBT_DEBUG("%s = %s",key,elem);
2147 * New methods to init the routing model component from the lua script
2152 * add a host to the network element list
2155 void routing_add_host(const char *host_id)
2157 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2161 * Set a new link on the actual list of link for a route or ASroute
2163 void routing_add_link(const char *link_id)
2165 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2169 *Set the endpoints for a route
2171 void routing_set_route(const char *src_id, const char *dst_id)
2173 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2177 * Store the route by calling parse_E_route_store_route
2179 void routing_store_route(void)
2181 parse_E_route_store_route();