1 /* Copyright (c) 2009, 2010, 2011. 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 */
9 #include "simgrid/platf_interface.h" // platform creation API internal interface
11 #include "surf_routing_private.h"
12 #include "surf/surf_routing.h"
13 #include "surf/surfxml_parse_values.h"
16 int ROUTING_HOST_LEVEL; //Routing level
17 int SURF_CPU_LEVEL; //Surf cpu level
18 int SURF_WKS_LEVEL; //Surf workstation level
19 int SIMIX_HOST_LEVEL; //Simix level
20 int MSG_HOST_LEVEL; //Msg level
21 int SD_HOST_LEVEL; //Simdag level
22 int COORD_HOST_LEVEL; //Coordinates level
23 int NS3_HOST_LEVEL; //host node for ns3
26 int SD_LINK_LEVEL; //Simdag level
27 int SURF_LINK_LEVEL; //Surf level
28 int NS3_LINK_LEVEL; //link for ns3
30 xbt_lib_t as_router_lib;
31 int ROUTING_ASR_LEVEL; //Routing level
32 int COORD_ASR_LEVEL; //Coordinates level
33 int NS3_ASR_LEVEL; //host node for ns3
35 static xbt_dict_t patterns = NULL;
36 static xbt_dict_t random_value = NULL;
39 routing_global_t global_routing = NULL;
40 routing_component_t current_routing = NULL;
41 model_type_t current_routing_model = NULL;
43 /* global parse functions */
44 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
45 static const char *src = NULL; /* temporary store the source name of a route */
46 static const char *dst = NULL; /* temporary store the destination name of a route */
47 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
48 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
49 static double_f_cpvoid_t get_link_latency = NULL;
50 xbt_dict_t cluster_host_link = NULL; /* for tag cluster */
52 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
54 static void routing_parse_Speer(void); /* peer bypass */
55 static void routing_parse_Srandom(void); /* random bypass */
56 static void routing_parse_Erandom(void); /* random bypass */
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);
176 * \brief Add a host to the network element list from XML
178 static void parse_S_host_XML(sg_platf_host_cbarg_t h)
180 parse_S_host(h->V_host_id, h->V_host_coord);
184 * \brief Add a "router" to the network element list
186 static void parse_S_router(sg_platf_router_cbarg_t router)
188 network_element_info_t info = NULL;
189 if (current_routing->hierarchy == SURF_ROUTING_NULL)
190 current_routing->hierarchy = SURF_ROUTING_BASE;
191 xbt_assert(!xbt_lib_get_or_null(as_router_lib,router->V_router_id, ROUTING_ASR_LEVEL),
192 "Reading a router, processing unit \"%s\" already exists",
193 router->V_router_id);
194 xbt_assert(current_routing->set_processing_unit,
195 "no defined method \"set_processing_unit\" in \"%s\"",
196 current_routing->name);
197 (*(current_routing->set_processing_unit)) (current_routing,
198 router->V_router_id);
199 info = xbt_new0(s_network_element_info_t, 1);
200 info->rc_component = current_routing;
201 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
203 xbt_lib_set(as_router_lib,router->V_router_id,ROUTING_ASR_LEVEL,(void *) info);
204 if (strcmp(A_surfxml_router_coordinates,"")) {
205 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
206 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
207 xbt_dynar_shrink(ctn, 0);
208 xbt_lib_set(as_router_lib,router->V_router_id,COORD_ASR_LEVEL,(void *) ctn);
213 * brief Add a "router" to the network element list from XML description
215 static void parse_S_router_lua(const char* router_id) {
216 s_sg_platf_router_cbarg_t router;
217 memset(&router,0,sizeof(router));
218 router.V_router_id = router_id;
219 router.V_router_coord = "";
220 return parse_S_router(&router);
224 * \brief Set the endponints for a route
226 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
228 if (src != NULL && dst != NULL && link_list != NULL)
229 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
233 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
234 "Some limits are null in the route between \"%s\" and \"%s\"",
236 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
240 * \brief Set the endpoints for a route from XML
242 static void parse_S_route_new_and_endpoints_XML(void)
244 parse_S_route_new_and_endpoints(A_surfxml_route_src,
245 A_surfxml_route_dst);
249 * \brief Set the endpoints for a route from lua
251 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
253 parse_S_route_new_and_endpoints(id_src, id_dst);
257 * \brief Set the endponints and gateways for a ASroute
259 static void parse_S_ASroute_new_and_endpoints(void)
261 if (src != NULL && dst != NULL && link_list != NULL)
262 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
263 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
264 src = A_surfxml_ASroute_src;
265 dst = A_surfxml_ASroute_dst;
266 gw_src = A_surfxml_ASroute_gw_src;
267 gw_dst = A_surfxml_ASroute_gw_dst;
268 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
269 || strlen(gw_dst) > 0,
270 "Some limits are null in the route between \"%s\" and \"%s\"",
272 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
276 * \brief Set the endponints for a bypassRoute
278 static void parse_S_bypassRoute_new_and_endpoints(void)
280 if (src != NULL && dst != NULL && link_list != NULL)
282 "Bypass Route between %s to %s can not be defined",
283 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
284 src = A_surfxml_bypassRoute_src;
285 dst = A_surfxml_bypassRoute_dst;
286 gw_src = A_surfxml_bypassRoute_gw_src;
287 gw_dst = A_surfxml_bypassRoute_gw_dst;
288 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
289 || strlen(gw_dst) > 0,
290 "Some limits are null in the route between \"%s\" and \"%s\"",
292 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
296 * \brief Set a new link on the actual list of link for a route or ASroute
298 static void parse_E_link_ctn_new_elem(const char *link_id)
301 val = xbt_strdup(link_id);
302 xbt_dynar_push(link_list, &val);
306 * \brief Set a new link on the actual list of link for a route or ASroute from XML
309 static void parse_E_link_ctn_new_elem_XML(void)
311 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
312 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
313 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
314 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
315 parse_E_link_ctn_new_elem(link_id);
318 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
319 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
320 parse_E_link_ctn_new_elem(link_id);
326 * \brief Set a new link on the actual list of link for a route or ASroute from lua
328 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
330 parse_E_link_ctn_new_elem(link_id);
334 * \brief Store the route by calling the set_route function of the current routing component
336 static void parse_E_route_store_route(void)
338 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
339 route->generic_route.link_list = link_list;
340 xbt_assert(current_routing->set_route,
341 "no defined method \"set_route\" in \"%s\"",
342 current_routing->name);
343 (*(current_routing->set_route)) (current_routing, src, dst, route);
350 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
352 static void parse_E_ASroute_store_route(void)
354 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
355 e_route->generic_route.link_list = link_list;
356 e_route->src_gateway = xbt_strdup(gw_src);
357 e_route->dst_gateway = xbt_strdup(gw_dst);
358 xbt_assert(current_routing->set_ASroute,
359 "no defined method \"set_ASroute\" in \"%s\"",
360 current_routing->name);
361 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
370 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
372 static void parse_E_bypassRoute_store_route(void)
374 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
375 e_route->generic_route.link_list = link_list;
376 e_route->src_gateway = xbt_strdup(gw_src);
377 e_route->dst_gateway = xbt_strdup(gw_dst);
378 xbt_assert(current_routing->set_bypassroute,
379 "no defined method \"set_bypassroute\" in \"%s\"",
380 current_routing->name);
381 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
391 * \brief Make a new routing component to the platform
393 * Add a new autonomous system to the platform. Any elements (such as host,
394 * router or sub-AS) added after this call and before the corresponding call
395 * to sg_platf_new_AS_close() will be added to this AS.
397 * Once this function was called, the configuration concerning the used
398 * models cannot be changed anymore.
400 * @param AS_id name of this autonomous system. Must be uniq in the platform
401 * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
403 void sg_platf_new_AS_open(const char *AS_id, const char *wanted_routing_type)
405 routing_component_t new_routing;
406 model_type_t model = NULL;
409 surf_parse_models_setup(); /* ensure that the models are created after the last <config> tag and before the first <AS>-like */
411 /* search the routing model */
412 for (cpt = 0; routing_models[cpt].name; cpt++)
413 if (!strcmp(wanted_routing_type, routing_models[cpt].name))
414 model = &routing_models[cpt];
415 /* if its not exist, error */
417 fprintf(stderr, "Routing model %s not found. Existing models:\n",
418 wanted_routing_type);
419 for (cpt = 0; routing_models[cpt].name; cpt++)
420 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
421 routing_models[cpt].desc);
425 /* make a new routing component */
426 new_routing = (routing_component_t) (*(model->create)) ();
427 new_routing->routing = model;
428 new_routing->hierarchy = SURF_ROUTING_NULL;
429 new_routing->name = xbt_strdup(AS_id);
430 new_routing->routing_sons = xbt_dict_new();
432 /* Hack for Vivaldi */
433 if(!strcmp(model->name,"Vivaldi"))
434 new_routing->get_latency = vivaldi_get_link_latency;
436 if (current_routing == NULL && global_routing->root == NULL) {
438 /* it is the first one */
439 new_routing->routing_father = NULL;
440 global_routing->root = new_routing;
442 } else if (current_routing != NULL && global_routing->root != NULL) {
444 xbt_assert(!xbt_dict_get_or_null
445 (current_routing->routing_sons, AS_id),
446 "The AS \"%s\" already exists", AS_id);
447 /* it is a part of the tree */
448 new_routing->routing_father = current_routing;
449 /* set the father behavior */
450 if (current_routing->hierarchy == SURF_ROUTING_NULL)
451 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
452 /* add to the sons dictionary */
453 xbt_dict_set(current_routing->routing_sons, AS_id,
454 (void *) new_routing, NULL);
455 /* add to the father element list */
456 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
457 /* unload the prev parse rules */
458 (*(current_routing->routing->unload)) ();
461 THROWF(arg_error, 0, "All defined components must be belong to a AS");
463 /* set the new parse rules */
464 (*(new_routing->routing->load)) ();
465 /* set the new current component of the tree */
466 current_routing = new_routing;
470 * \brief Specify that the current description of AS is finished
472 * Once you've declared all the content of your AS, you have to close
473 * it with this call. Your AS is not usable until you call this function.
475 * @fixme: this call is not as robust as wanted: bad things WILL happen
476 * if you call it twice for the same AS, or if you forget calling it, or
477 * even if you add stuff to a closed AS
480 void sg_platf_new_AS_close() {
482 if (current_routing == NULL) {
483 THROWF(arg_error, 0, "Close an AS, but none was under construction");
485 network_element_info_t info = NULL;
486 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
487 "The AS \"%s\" already exists",current_routing->name);
488 info = xbt_new0(s_network_element_info_t, 1);
489 info->rc_component = current_routing->routing_father;
490 info->rc_type = SURF_NETWORK_ELEMENT_AS;
491 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
493 (*(current_routing->routing->unload)) ();
494 (*(current_routing->routing->end)) ();
495 current_routing = current_routing->routing_father;
496 if (current_routing != NULL)
497 (*(current_routing->routing->load)) ();
501 /* Aux Business methods */
504 * \brief Get the AS name of the element
506 * \param name the host name
509 static char* elements_As_name(const char *name)
511 routing_component_t as_comp;
513 /* (1) find the as where the host is located */
514 as_comp = ((network_element_info_t)
515 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
516 return as_comp->name;
521 * \brief Get the AS father and the first elements of the chain
523 * \param src the source host name
524 * \param dst the destination host name
526 * Get the common father of the to processing units, and the first different
527 * father in the chain
529 static void elements_father(const char *src, const char *dst,
530 routing_component_t *res_father,
531 routing_component_t *res_src,
532 routing_component_t *res_dst)
534 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
535 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
536 routing_component_t src_as, dst_as;
537 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
538 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
541 routing_component_t current;
542 routing_component_t current_src;
543 routing_component_t current_dst;
544 routing_component_t father;
546 /* (1) find the as where the src and dst are located */
547 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
549 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
552 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
554 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
555 src_as = src_data->rc_component;
556 dst_as = dst_data->rc_component;
558 xbt_assert(src_as && dst_as,
559 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
561 /* (2) find the path to the root routing component */
562 for (current = src_as ; current != NULL ; current = current->routing_father) {
563 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
564 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
565 path_src[index_src++] = current;
567 for (current = dst_as ; current != NULL ; current = current->routing_father) {
568 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
569 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
570 path_dst[index_dst++] = current;
573 /* (3) find the common father */
575 current_src = path_src[--index_src];
576 current_dst = path_dst[--index_dst];
577 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
579 /* (4) they are not in the same routing component, make the path */
580 if (current_src == current_dst)
581 father = current_src;
583 father = path_src[index_src + 1];
585 /* (5) result generation */
586 *res_father = father; /* first the common father of src and dst */
587 *res_src = current_src; /* second the first different father of src */
588 *res_dst = current_dst; /* three the first different father of dst */
590 #undef ELEMENTS_FATHER_MAXDEPTH
593 /* Global Business methods */
596 * \brief Recursive function for get_route_latency
598 * \param src the source host name
599 * \param dst the destination host name
600 * \param *e_route the route where the links are stored
601 * \param *latency the latency, if needed
603 * This function is called by "get_route" and "get_latency". It allows to walk
604 * recursively through the routing components tree.
606 static void _get_route_latency(const char *src, const char *dst,
607 xbt_dynar_t *route, double *latency)
609 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
610 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
612 routing_component_t common_father;
613 routing_component_t src_father;
614 routing_component_t dst_father;
615 elements_father(src, dst, &common_father, &src_father, &dst_father);
617 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
619 route_extended_t e_route = NULL;
621 e_route = common_father->get_route(common_father, src, dst);
622 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
623 *route = e_route->generic_route.link_list;
626 *latency = common_father->get_latency(common_father, src, dst, e_route);
627 xbt_assert(*latency >= 0.0,
628 "latency error on route between \"%s\" and \"%s\"", src, dst);
631 xbt_free(e_route->src_gateway);
632 xbt_free(e_route->dst_gateway);
636 } else { /* SURF_ROUTING_RECURSIVE */
638 route_extended_t e_route_bypass = NULL;
639 if (common_father->get_bypass_route)
640 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
642 xbt_assert(!latency || !e_route_bypass,
643 "Bypass cannot work yet with get_latency");
645 route_extended_t e_route_cnt = e_route_bypass
647 : common_father->get_route(common_father,
648 src_father->name, dst_father->name);
650 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
651 src_father->name, dst_father->name);
653 xbt_assert((e_route_cnt->src_gateway == NULL) ==
654 (e_route_cnt->dst_gateway == NULL),
655 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
658 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
661 *latency = common_father->get_latency(common_father,
662 src_father->name, dst_father->name,
664 xbt_assert(*latency >= 0.0,
665 "latency error on route between \"%s\" and \"%s\"",
666 src_father->name, dst_father->name);
672 if (strcmp(src, e_route_cnt->src_gateway)) {
674 xbt_dynar_t route_src;
676 _get_route_latency(src, e_route_cnt->src_gateway,
677 (route ? &route_src : NULL),
678 (latency ? &latency_src : NULL));
680 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
681 src, e_route_cnt->src_gateway);
682 xbt_dynar_foreach(route_src, cpt, link) {
683 xbt_dynar_push(*route, &link);
685 xbt_dynar_free(&route_src);
688 xbt_assert(latency_src >= 0.0,
689 "latency error on route between \"%s\" and \"%s\"",
690 src, e_route_cnt->src_gateway);
691 *latency += latency_src;
696 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
697 xbt_dynar_push(*route, &link);
701 if (strcmp(e_route_cnt->dst_gateway, dst)) {
703 xbt_dynar_t route_dst;
705 _get_route_latency(e_route_cnt->dst_gateway, dst,
706 (route ? &route_dst : NULL),
707 (latency ? &latency_dst : NULL));
709 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
710 e_route_cnt->dst_gateway, dst);
711 xbt_dynar_foreach(route_dst, cpt, link) {
712 xbt_dynar_push(*route, &link);
714 xbt_dynar_free(&route_dst);
717 xbt_assert(latency_dst >= 0.0,
718 "latency error on route between \"%s\" and \"%s\"",
719 e_route_cnt->dst_gateway, dst);
720 *latency += latency_dst;
724 generic_free_extended_route(e_route_cnt);
729 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
731 static void get_route_latency(const char *src, const char *dst,
732 xbt_dynar_t *route, double *latency, int cleanup)
734 _get_route_latency(src, dst, route, latency);
735 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
736 xbt_assert(!latency || *latency >= 0.0,
737 "latency error on route between \"%s\" and \"%s\"", src, dst);
739 xbt_dynar_free(&global_routing->last_route);
740 global_routing->last_route = cleanup ? *route : NULL;
745 * \brief Generic method: find a route between hosts
747 * \param src the source host name
748 * \param dst the destination host name
750 * walk through the routing components tree and find a route between hosts
751 * by calling the differents "get_route" functions in each routing component.
752 * No need to free the returned dynar. It will be freed at the next call.
754 static xbt_dynar_t get_route(const char *src, const char *dst)
756 xbt_dynar_t route = NULL;
757 get_route_latency(src, dst, &route, NULL, 1);
762 * \brief Generic method: find a route between hosts
764 * \param src the source host name
765 * \param dst the destination host name
767 * same as get_route, but return NULL if any exception is raised.
769 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
771 xbt_dynar_t route = NULL;
774 get_route_latency(src, dst, &route, NULL, 1);
776 xbt_ex_free(exception);
783 * \brief Generic method: find a route between hosts
785 * \param src the source host name
786 * \param dst the destination host name
788 * walk through the routing components tree and find a route between hosts
789 * by calling the differents "get_route" functions in each routing component.
790 * Leaves the caller the responsability to clean the returned dynar.
792 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
794 xbt_dynar_t route = NULL;
795 get_route_latency(src, dst, &route, NULL, 0);
800 static double get_latency(const char *src, const char *dst)
802 double latency = -1.0;
803 get_route_latency(src, dst, NULL, &latency, 0);
807 static int surf_parse_models_setup_already_called=0;
808 /* Call the last initialization functions, that must be called after the
809 * <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
811 void surf_parse_models_setup()
813 if (surf_parse_models_setup_already_called)
815 surf_parse_models_setup_already_called=1;
816 routing_parse_Erandom();
817 surf_config_models_setup();
822 * \brief Recursive function for finalize
824 * \param rc the source host name
826 * This fuction is call by "finalize". It allow to finalize the
827 * AS or routing components. It delete all the structures.
829 static void _finalize(routing_component_t rc)
832 xbt_dict_cursor_t cursor = NULL;
834 routing_component_t elem;
835 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
838 xbt_dict_t tmp_sons = rc->routing_sons;
839 char *tmp_name = rc->name;
840 xbt_dict_free(&tmp_sons);
842 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
843 current_routing->name);
844 (*(rc->finalize)) (rc);
849 * \brief Generic method: delete all the routing structures
851 * walk through the routing components tree and delete the structures
852 * by calling the differents "finalize" functions in each routing component
854 static void finalize(void)
856 /* delete recursibly all the tree */
857 _finalize(global_routing->root);
858 /* delete last_route */
859 xbt_dynar_free(&(global_routing->last_route));
860 /* delete global routing structure */
861 xbt_free(global_routing);
862 /* make sure that we will reinit the models while loading the platf once reinited -- HACK but there is no proper surf_routing_init() */
863 surf_parse_models_setup_already_called = 0;
866 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
868 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
870 //adding my one link routes
873 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
875 xbt_dynar_foreach(onelink_mine, cpt, link) {
876 xbt_dynar_push(ret, &link);
881 xbt_dict_cursor_t cursor = NULL;
882 routing_component_t rc_child;
883 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
884 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
886 xbt_dynar_foreach(onelink_child, cpt, link) {
887 xbt_dynar_push(ret, &link);
894 static xbt_dynar_t get_onelink_routes(void)
896 return recursive_get_onelink_routes(global_routing->root);
899 e_surf_network_element_type_t get_network_element_type(const char
902 network_element_info_t rc = NULL;
904 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
905 if(rc) return rc->rc_type;
907 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
908 if(rc) return rc->rc_type;
910 return SURF_NETWORK_ELEMENT_NULL;
914 * \brief Generic method: create the global routing schema
916 * Make a global routing structure and set all the parsing functions.
918 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
920 /* config the uniq global routing */
921 global_routing = xbt_new0(s_routing_global_t, 1);
922 global_routing->root = NULL;
923 global_routing->get_route = get_route;
924 global_routing->get_route_or_null = get_route_or_null;
925 global_routing->get_latency = get_latency;
926 global_routing->get_route_no_cleanup = get_route_no_cleanup;
927 global_routing->get_onelink_routes = get_onelink_routes;
928 global_routing->get_route_latency = get_route_latency;
929 global_routing->get_network_element_type = get_network_element_type;
930 global_routing->finalize = finalize;
931 global_routing->loopback = loopback;
932 global_routing->size_of_link = size_of_links;
933 global_routing->last_route = NULL;
934 get_link_latency = get_link_latency_fun;
935 /* no current routing at moment */
936 current_routing = NULL;
938 /* parse generic elements */
939 sg_platf_host_add_cb(parse_S_host_XML);
940 sg_platf_router_add_cb(parse_S_router);
942 surfxml_add_callback(STag_surfxml_route_cb_list,
943 &parse_S_route_new_and_endpoints_XML);
944 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
945 &parse_S_ASroute_new_and_endpoints);
946 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
947 &parse_S_bypassRoute_new_and_endpoints);
949 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
950 &parse_E_link_ctn_new_elem_XML);
952 surfxml_add_callback(ETag_surfxml_route_cb_list,
953 &parse_E_route_store_route);
954 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
955 &parse_E_ASroute_store_route);
956 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
957 &parse_E_bypassRoute_store_route);
959 surfxml_add_callback(STag_surfxml_cluster_cb_list,
960 &routing_parse_Scluster);
962 surfxml_add_callback(STag_surfxml_peer_cb_list,
963 &routing_parse_Speer);
965 surfxml_add_callback(ETag_surfxml_platform_cb_list,
966 &clean_routing_after_parse);
969 instr_routing_define_callbacks();
973 void surf_parse_add_callback_config(void)
975 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
976 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
979 /* ************************************************** */
980 /* ********** PATERN FOR NEW ROUTING **************** */
982 /* The minimal configuration of a new routing model need the next functions,
983 * also you need to set at the start of the file, the new model in the model
984 * list. Remember keep the null ending of the list.
986 /*** Routing model structure ***/
988 // s_routing_component_t generic_routing;
989 // /* things that your routing model need */
990 // } s_routing_component_NEW_t,*routing_component_NEW_t;
992 /*** Parse routing model functions ***/
993 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
994 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
995 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
996 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
997 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
999 /*** Business methods ***/
1000 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1001 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1002 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1004 /*** Creation routing model functions ***/
1005 // static void* model_NEW_create(void) {
1006 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1007 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1008 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1009 // new_component->generic_routing.set_route = model_NEW_set_route;
1010 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1011 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1012 // new_component->generic_routing.get_route = NEW_get_route;
1013 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1014 // new_component->generic_routing.finalize = NEW_finalize;
1015 // /* initialization of internal structures */
1016 // return new_component;
1017 // } /* mandatory */
1018 // static void model_NEW_load(void) {} /* mandatory */
1019 // static void model_NEW_unload(void) {} /* mandatory */
1020 // static void model_NEW_end(void) {} /* mandatory */
1022 /* ************************************************************************** */
1023 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1025 void generic_set_processing_unit(routing_component_t rc,
1028 XBT_DEBUG("Load process unit \"%s\"", name);
1029 int *id = xbt_new0(int, 1);
1030 xbt_dict_t _to_index;
1031 _to_index = current_routing->to_index;
1032 *id = xbt_dict_length(_to_index);
1033 xbt_dict_set(_to_index, name, id, xbt_free);
1036 void generic_set_autonomous_system(routing_component_t rc,
1039 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1040 int *id = xbt_new0(int, 1);
1041 xbt_dict_t _to_index;
1042 _to_index = current_routing->to_index;
1043 *id = xbt_dict_length(_to_index);
1044 xbt_dict_set(_to_index, name, id, xbt_free);
1047 int surf_pointer_resource_cmp(const void *a, const void *b)
1052 int surf_link_resource_cmp(const void *a, const void *b)
1054 return !!memcmp(a,b,global_routing->size_of_link);
1057 void generic_set_bypassroute(routing_component_t rc,
1058 const char *src, const char *dst,
1059 route_extended_t e_route)
1061 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1062 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1065 route_name = bprintf("%s#%s", src, dst);
1066 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1067 "Invalid count of links, must be greater than zero (%s,%s)",
1069 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1070 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1071 src, e_route->src_gateway, dst, e_route->dst_gateway);
1073 route_extended_t new_e_route =
1074 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1075 xbt_dynar_free(&(e_route->generic_route.link_list));
1078 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1079 (void (*)(void *)) generic_free_extended_route);
1080 xbt_free(route_name);
1083 /* ************************************************************************** */
1084 /* *********************** GENERIC BUSINESS METHODS ************************* */
1086 double generic_get_link_latency(routing_component_t rc,
1087 const char *src, const char *dst,
1088 route_extended_t route)
1090 int need_to_clean = route?0:1;
1093 double latency = 0.0;
1095 route = route?route:rc->get_route(rc,src,dst);
1097 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1098 latency += get_link_latency(link);
1100 if(need_to_clean) generic_free_extended_route(route);
1104 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1106 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1109 route_extended_t generic_get_bypassroute(routing_component_t rc,
1113 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1114 routing_component_t src_as, dst_as;
1115 int index_src, index_dst;
1116 xbt_dynar_t path_src = NULL;
1117 xbt_dynar_t path_dst = NULL;
1118 routing_component_t current = NULL;
1119 routing_component_t *current_src = NULL;
1120 routing_component_t *current_dst = NULL;
1122 /* (1) find the as where the src and dst are located */
1123 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1124 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1125 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1126 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1128 if(src_data == NULL || dst_data == NULL)
1129 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1130 src, dst, rc->name);
1132 src_as = ((network_element_info_t)src_data)->rc_component;
1133 dst_as = ((network_element_info_t)dst_data)->rc_component;
1135 /* (2) find the path to the root routing component */
1136 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1138 while (current != NULL) {
1139 xbt_dynar_push(path_src, ¤t);
1140 current = current->routing_father;
1142 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1144 while (current != NULL) {
1145 xbt_dynar_push(path_dst, ¤t);
1146 current = current->routing_father;
1149 /* (3) find the common father */
1150 index_src = path_src->used - 1;
1151 index_dst = path_dst->used - 1;
1152 current_src = xbt_dynar_get_ptr(path_src, index_src);
1153 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1154 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1155 xbt_dynar_pop_ptr(path_src);
1156 xbt_dynar_pop_ptr(path_dst);
1159 current_src = xbt_dynar_get_ptr(path_src, index_src);
1160 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1163 int max_index_src = path_src->used - 1;
1164 int max_index_dst = path_dst->used - 1;
1166 int max_index = max(max_index_src, max_index_dst);
1169 route_extended_t e_route_bypass = NULL;
1171 for (max = 0; max <= max_index; max++) {
1172 for (i = 0; i < max; i++) {
1173 if (i <= max_index_src && max <= max_index_dst) {
1174 char *route_name = bprintf("%s#%s",
1175 (*(routing_component_t *)
1177 (path_src, i)))->name,
1178 (*(routing_component_t *)
1180 (path_dst, max)))->name);
1182 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1183 xbt_free(route_name);
1187 if (max <= max_index_src && i <= max_index_dst) {
1188 char *route_name = bprintf("%s#%s",
1189 (*(routing_component_t *)
1191 (path_src, max)))->name,
1192 (*(routing_component_t *)
1194 (path_dst, i)))->name);
1196 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1197 xbt_free(route_name);
1206 if (max <= max_index_src && max <= max_index_dst) {
1207 char *route_name = bprintf("%s#%s",
1208 (*(routing_component_t *)
1210 (path_src, max)))->name,
1211 (*(routing_component_t *)
1213 (path_dst, max)))->name);
1214 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1215 xbt_free(route_name);
1221 xbt_dynar_free(&path_src);
1222 xbt_dynar_free(&path_dst);
1224 route_extended_t new_e_route = NULL;
1226 if (e_route_bypass) {
1228 unsigned int cpt = 0;
1229 new_e_route = xbt_new0(s_route_extended_t, 1);
1230 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1231 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1232 new_e_route->generic_route.link_list =
1233 xbt_dynar_new(global_routing->size_of_link, NULL);
1234 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1235 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1242 /* ************************************************************************** */
1243 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1246 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1247 void *data, int order)
1253 xbt_dynar_t links = NULL, links_id = NULL;
1255 new_route = xbt_new0(s_route_t, 1);
1256 new_route->link_list =
1257 xbt_dynar_new(global_routing->size_of_link, NULL);
1259 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1260 "the hierarchy type is not SURF_ROUTING_BASE");
1262 links = ((route_t) data)->link_list;
1265 links_id = new_route->link_list;
1267 xbt_dynar_foreach(links, cpt, link_name) {
1270 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1273 xbt_dynar_push(links_id, &link);
1275 xbt_dynar_unshift(links_id, &link);
1277 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1284 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1285 void *data, int order)
1289 route_extended_t e_route, new_e_route;
1292 xbt_dynar_t links = NULL, links_id = NULL;
1294 new_e_route = xbt_new0(s_route_extended_t, 1);
1295 new_e_route->generic_route.link_list =
1296 xbt_dynar_new(global_routing->size_of_link, NULL);
1297 new_e_route->src_gateway = NULL;
1298 new_e_route->dst_gateway = NULL;
1300 xbt_assert(hierarchy == SURF_ROUTING_BASE
1301 || hierarchy == SURF_ROUTING_RECURSIVE,
1302 "the hierarchy type is not defined");
1304 if (hierarchy == SURF_ROUTING_BASE) {
1306 route = (route_t) data;
1307 links = route->link_list;
1309 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1311 e_route = (route_extended_t) data;
1312 xbt_assert(e_route->src_gateway
1313 && e_route->dst_gateway, "bad gateway, is null");
1314 links = e_route->generic_route.link_list;
1316 /* remeber not erase the gateway names */
1317 new_e_route->src_gateway = strdup(e_route->src_gateway);
1318 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1321 links_id = new_e_route->generic_route.link_list;
1323 xbt_dynar_foreach(links, cpt, link_name) {
1326 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1329 xbt_dynar_push(links_id, &link);
1331 xbt_dynar_unshift(links_id, &link);
1333 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1339 void generic_free_route(route_t route)
1342 xbt_dynar_free(&(route->link_list));
1347 void generic_free_extended_route(route_extended_t e_route)
1350 xbt_dynar_free(&(e_route->generic_route.link_list));
1351 if (e_route->src_gateway)
1352 xbt_free(e_route->src_gateway);
1353 if (e_route->dst_gateway)
1354 xbt_free(e_route->dst_gateway);
1359 static routing_component_t generic_as_exist(routing_component_t find_from,
1360 routing_component_t to_find)
1362 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1363 xbt_dict_cursor_t cursor = NULL;
1366 routing_component_t elem;
1367 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1368 if (to_find == elem || generic_as_exist(elem, to_find)) {
1379 generic_autonomous_system_exist(routing_component_t rc, char *element)
1381 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1382 routing_component_t element_as, result, elem;
1383 xbt_dict_cursor_t cursor = NULL;
1385 element_as = ((network_element_info_t)
1386 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1387 result = ((routing_component_t) - 1);
1388 if (element_as != rc)
1389 result = generic_as_exist(rc, element_as);
1393 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1394 found = !strcmp(elem->name, element);
1405 generic_processing_units_exist(routing_component_t rc, char *element)
1407 routing_component_t element_as;
1408 element_as = ((network_element_info_t)
1409 xbt_lib_get_or_null(host_lib,
1410 element, ROUTING_HOST_LEVEL))->rc_component;
1411 if (element_as == rc)
1413 return generic_as_exist(rc, element_as);
1416 void generic_src_dst_check(routing_component_t rc, const char *src,
1420 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1421 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1422 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1423 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1425 if(src_data == NULL || dst_data == NULL)
1426 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1427 src, dst, rc->name);
1429 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1430 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1432 if(src_as != dst_as)
1433 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1434 src, src_as->name, dst, dst_as->name);
1436 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1437 src,dst,src_as->name, dst_as->name,rc->name);
1440 void routing_parse_Scluster(void)
1442 if(!cluster_host_link)
1443 cluster_host_link = xbt_dict_new();
1445 static int AX_ptr = 0;
1446 char *host_id, *groups, *link_id = NULL;
1448 s_sg_platf_host_cbarg_t host;
1450 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1451 || strcmp(struct_cluster->V_cluster_state_file,"") )
1453 if(xbt_dict_size(patterns)==0)
1454 patterns = xbt_dict_new();
1455 xbt_dict_set(patterns,"id",struct_cluster->V_cluster_id,NULL);
1456 xbt_dict_set(patterns,"prefix",struct_cluster->V_cluster_prefix,NULL);
1457 xbt_dict_set(patterns,"suffix",struct_cluster->V_cluster_suffix,NULL);
1462 xbt_dynar_t radical_elements;
1463 xbt_dynar_t radical_ends;
1465 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1466 static unsigned int surfxml_buffer_stack_stack[1024];
1468 surfxml_buffer_stack_stack[0] = 0;
1469 surfxml_bufferstack_push(1);
1471 SURFXML_BUFFER_SET(AS_id, struct_cluster->V_cluster_id);
1472 SURFXML_BUFFER_SET(AS_routing, "Cluster");
1473 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", struct_cluster->V_cluster_id);
1474 SURFXML_START_TAG(AS);
1477 radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ",");
1478 xbt_dynar_foreach(radical_elements, iter, groups) {
1479 memset(&host,0,sizeof(host));
1481 radical_ends = xbt_str_split(groups, "-");
1482 switch (xbt_dynar_length(radical_ends)) {
1484 start=surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1485 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, start, struct_cluster->V_cluster_suffix);
1486 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start);
1488 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1489 host.V_host_id = host_id;
1490 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1491 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1492 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1493 xbt_str_varsubst(tmp_availability_file,patterns);
1494 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1495 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1496 xbt_free(tmp_availability_file);
1500 XBT_DEBUG("\tavailability_file=\"\"");
1502 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1503 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1504 xbt_str_varsubst(tmp_state_file,patterns);
1505 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1506 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1507 xbt_free(tmp_state_file);
1511 XBT_DEBUG("\tstate_file=\"\"");
1514 host.V_host_power_peak = struct_cluster->S_cluster_power;
1515 host.V_host_power_scale = 1.0;
1516 host.V_host_core = struct_cluster->S_cluster_core;
1517 host.V_host_state_initial = SURF_RESOURCE_ON;
1518 host.V_host_coord = "";
1519 sg_platf_new_host(&host);
1520 XBT_DEBUG("</host>");
1522 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1523 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1524 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1525 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1526 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1528 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1530 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1531 struct_lnk->V_link_id = link_id;
1532 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1533 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1534 struct_lnk->V_link_bandwidth_file = NULL;
1535 struct_lnk->V_link_latency_file = NULL;
1536 struct_lnk->V_link_state_file = NULL;
1537 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1538 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1540 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1541 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1544 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1545 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1546 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1547 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1551 ETag_surfxml_link();
1553 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1554 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX){
1555 char* tmp_link = bprintf("%s_UP",link_id);
1556 info->link_up = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1558 tmp_link = bprintf("%s_DOWN",link_id);
1559 info->link_down = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1563 info->link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
1564 info->link_down = info->link_up;
1566 xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
1574 start=surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1575 end= surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
1576 for (i = start; i <= end; i++) {
1577 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1578 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1580 A_surfxml_host_state = A_surfxml_host_state_ON;
1582 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1583 host.V_host_id = host_id;
1584 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1585 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1586 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1587 xbt_str_varsubst(tmp_availability_file,patterns);
1588 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1589 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1590 xbt_free(tmp_availability_file);
1594 XBT_DEBUG("\tavailability_file=\"\"");
1596 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1597 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1598 xbt_str_varsubst(tmp_state_file,patterns);
1599 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1600 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1601 xbt_free(tmp_state_file);
1605 XBT_DEBUG("\tstate_file=\"\"");
1608 host.V_host_power_peak = struct_cluster->S_cluster_power;
1609 host.V_host_power_scale = 1.0;
1610 host.V_host_core = struct_cluster->S_cluster_core;
1611 host.V_host_state_initial = SURF_RESOURCE_ON;
1612 host.V_host_coord = "";
1613 sg_platf_new_host(&host);
1614 XBT_DEBUG("</host>");
1616 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1617 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1618 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1619 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1620 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1622 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1624 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1625 struct_lnk->V_link_id = link_id;
1626 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1627 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1628 struct_lnk->V_link_bandwidth_file = NULL;
1629 struct_lnk->V_link_latency_file = NULL;
1630 struct_lnk->V_link_state_file = NULL;
1631 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1632 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1634 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1635 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1638 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1639 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1640 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1641 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1645 ETag_surfxml_link();
1647 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1648 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX){
1649 char* tmp_link = bprintf("%s_UP",link_id);
1650 info->link_up = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1652 tmp_link = bprintf("%s_DOWN",link_id);
1653 info->link_down = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1657 info->link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
1658 info->link_down = info->link_up;
1660 xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
1668 XBT_DEBUG("Malformed radical");
1672 xbt_dynar_free(&radical_ends);
1674 xbt_dynar_free(&radical_elements);
1678 XBT_DEBUG("<router id=\"%s\"/>", struct_cluster->S_cluster_router_id);
1679 SURFXML_BUFFER_SET(router_id, struct_cluster->S_cluster_router_id);
1680 SURFXML_BUFFER_SET(router_coordinates, "");
1681 SURFXML_START_TAG(router);
1682 SURFXML_END_TAG(router);
1685 if( (struct_cluster->S_cluster_bb_bw!= 0) && (struct_cluster->S_cluster_bb_lat!=0) ){
1686 char *link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1687 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,struct_cluster->S_cluster_bb_bw, struct_cluster->S_cluster_bb_lat);
1689 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1690 if(AX_surfxml_cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1691 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1693 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1694 struct_lnk->V_link_id = link_backbone;
1695 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bb_bw;
1696 struct_lnk->V_link_latency = struct_cluster->S_cluster_bb_lat;
1697 struct_lnk->V_link_bandwidth_file = NULL;
1698 struct_lnk->V_link_latency_file = NULL;
1699 struct_lnk->V_link_state_file = NULL;
1700 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1701 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1703 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1704 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1706 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1709 ETag_surfxml_link();
1711 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1712 info->link_up = xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL);
1713 info->link_down = info->link_up;
1714 xbt_dict_set(cluster_host_link,struct_cluster->V_cluster_id,info,xbt_free);
1715 free(link_backbone);
1720 char *new_suffix = xbt_strdup("");
1722 radical_elements = xbt_str_split(struct_cluster->V_cluster_suffix, ".");
1723 xbt_dynar_foreach(radical_elements, iter, groups) {
1724 if (strcmp(groups, "")) {
1725 char *old_suffix = new_suffix;
1726 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1731 xbt_dynar_free(&radical_elements);
1732 xbt_free(new_suffix);
1734 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1735 || strcmp(struct_cluster->V_cluster_state_file,"") )
1736 xbt_dict_free(&patterns);
1739 SURFXML_END_TAG(AS);
1742 surfxml_bufferstack_pop(1);
1745 * This function take a string and replace parameters from patterns dict.
1746 * It returns the new value.
1748 static char* replace_random_parameter(char * string)
1750 char *test_string = NULL;
1752 if(xbt_dict_size(random_value)==0)
1755 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1756 test_string = bprintf("${%s}", string);
1757 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1759 if (strcmp(test_string,"")) { //if not empty, keep this value.
1761 string = test_string;
1762 } //In other case take old value (without ${})
1768 static void clean_routing_after_parse(void)
1770 xbt_dict_free(&random_value);
1771 xbt_dict_free(&patterns);
1774 static void routing_parse_Speer(void)
1776 static int AX_ptr = 0;
1777 char *host_id = NULL;
1778 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1780 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1781 static unsigned int surfxml_buffer_stack_stack[1024];
1783 surfxml_buffer_stack_stack[0] = 0;
1785 surfxml_bufferstack_push(1);
1787 SURFXML_BUFFER_SET(AS_id, struct_peer->V_peer_id);
1789 SURFXML_BUFFER_SET(AS_routing, "Full");
1790 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->V_peer_id);
1792 SURFXML_START_TAG(AS);
1795 host_id = bprintf("peer_%s", struct_peer->V_peer_id);
1796 router_id = bprintf("router_%s", struct_peer->V_peer_id);
1797 link_id_up = bprintf("link_%s_up", struct_peer->V_peer_id);
1798 link_id_down = bprintf("link_%s_down", struct_peer->V_peer_id);
1800 link_router = bprintf("%s_link_router", struct_peer->V_peer_id);
1801 link_backbone = bprintf("%s_backbone", struct_peer->V_peer_id);
1803 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, struct_peer->V_peer_power);
1804 A_surfxml_host_state = A_surfxml_host_state_ON;
1805 SURFXML_BUFFER_SET(host_id, host_id);
1806 SURFXML_BUFFER_SET(host_power, struct_peer->V_peer_power);
1807 SURFXML_BUFFER_SET(host_availability, "1.0");
1808 SURFXML_BUFFER_SET(host_availability_file, struct_peer->V_peer_availability_trace);
1809 SURFXML_BUFFER_SET(host_state_file, struct_peer->V_peer_state_trace);
1810 SURFXML_BUFFER_SET(host_coordinates, "");
1811 SURFXML_BUFFER_SET(host_core, "1.0");
1812 SURFXML_START_TAG(host);
1813 SURFXML_END_TAG(host);
1815 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->V_peer_coord);
1816 SURFXML_BUFFER_SET(router_id, router_id);
1817 SURFXML_BUFFER_SET(router_coordinates, struct_peer->V_peer_coord);
1818 SURFXML_START_TAG(router);
1819 SURFXML_END_TAG(router);
1821 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, struct_peer->V_peer_bw_in, struct_peer->V_peer_lat);
1822 A_surfxml_link_state = A_surfxml_link_state_ON;
1823 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1824 SURFXML_BUFFER_SET(link_id, link_id_up);
1825 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_in);
1826 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1827 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1828 SURFXML_BUFFER_SET(link_latency_file, "");
1829 SURFXML_BUFFER_SET(link_state_file, "");
1830 SURFXML_START_TAG(link);
1831 SURFXML_END_TAG(link);
1833 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, struct_peer->V_peer_bw_out, struct_peer->V_peer_lat);
1834 A_surfxml_link_state = A_surfxml_link_state_ON;
1835 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1836 SURFXML_BUFFER_SET(link_id, link_id_down);
1837 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_out);
1838 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1839 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1840 SURFXML_BUFFER_SET(link_latency_file, "");
1841 SURFXML_BUFFER_SET(link_state_file, "");
1842 SURFXML_START_TAG(link);
1843 SURFXML_END_TAG(link);
1848 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1849 XBT_DEBUG("symmetrical=\"NO\">");
1850 SURFXML_BUFFER_SET(route_src, host_id);
1851 SURFXML_BUFFER_SET(route_dst, router_id);
1852 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1853 SURFXML_START_TAG(route);
1855 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1856 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1857 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1858 SURFXML_START_TAG(link_ctn);
1859 SURFXML_END_TAG(link_ctn);
1861 XBT_DEBUG("</route>");
1862 SURFXML_END_TAG(route);
1865 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1866 XBT_DEBUG("symmetrical=\"NO\">");
1867 SURFXML_BUFFER_SET(route_src, router_id);
1868 SURFXML_BUFFER_SET(route_dst, host_id);
1869 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1870 SURFXML_START_TAG(route);
1872 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
1873 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
1874 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1875 SURFXML_START_TAG(link_ctn);
1876 SURFXML_END_TAG(link_ctn);
1878 XBT_DEBUG("</route>");
1879 SURFXML_END_TAG(route);
1882 SURFXML_END_TAG(AS);
1885 //xbt_dynar_free(&tab_elements_num);
1889 free(link_backbone);
1892 surfxml_bufferstack_pop(1);
1895 static void routing_parse_Srandom(void)
1897 double mean, std, min, max, seed;
1898 char *random_id = A_surfxml_random_id;
1899 char *random_radical = A_surfxml_random_radical;
1900 char *rd_name = NULL;
1902 mean = surf_parse_get_double(A_surfxml_random_mean);
1903 std = surf_parse_get_double(A_surfxml_random_std_deviation);
1904 min = surf_parse_get_double(A_surfxml_random_min);
1905 max = surf_parse_get_double(A_surfxml_random_max);
1906 seed = surf_parse_get_double(A_surfxml_random_seed);
1910 random_data_t random = xbt_new0(s_random_data_t, 1);
1913 xbt_dynar_t radical_elements;
1917 xbt_dynar_t radical_ends;
1919 random->generator = A_surfxml_random_generator;
1920 random->seed = seed;
1924 /* Check user stupidities */
1926 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
1928 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
1931 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
1934 /* normalize the mean and standard deviation before storing */
1935 random->mean = (mean - min) / (max - min);
1936 random->std = std / (max - min);
1938 if (random->mean * (1 - random->mean) < random->std * random->std)
1939 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
1940 random->mean, random->std);
1942 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
1952 if(xbt_dict_size(random_value)==0)
1953 random_value = xbt_dict_new();
1955 if(!strcmp(random_radical,""))
1957 res = random_generate(random);
1958 rd_value = bprintf("%f",res);
1959 xbt_dict_set(random_value, random_id, rd_value, free);
1963 radical_elements = xbt_str_split(random_radical, ",");
1964 xbt_dynar_foreach(radical_elements, iter, groups) {
1965 radical_ends = xbt_str_split(groups, "-");
1966 switch (xbt_dynar_length(radical_ends)) {
1968 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
1969 res = random_generate(random);
1970 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
1971 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
1976 start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1977 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
1978 for (i = start; i <= end; i++) {
1979 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
1980 res = random_generate(random);
1981 tmpbuf = bprintf("%s%d",random_id,i);
1982 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
1987 XBT_INFO("Malformed radical");
1990 res = random_generate(random);
1991 rd_name = bprintf("%s_router",random_id);
1992 rd_value = bprintf("%f",res);
1993 xbt_dict_set(random_value, rd_name, rd_value, free);
1995 xbt_dynar_free(&radical_ends);
1998 xbt_dynar_free(&radical_elements);
2002 static void routing_parse_Erandom(void)
2004 /*xbt_dict_cursor_t cursor = NULL;
2008 xbt_dict_foreach(random_value, cursor, key, elem) {
2009 XBT_DEBUG("%s = %s",key,elem);
2015 * New methods to init the routing model component from the lua script
2020 * add a host to the network element list
2023 void routing_add_host(const char *host_id)
2025 parse_S_host(host_id, ""); // FIXME propagate coordinate system to lua
2029 * Set a new link on the actual list of link for a route or ASroute
2031 void routing_add_link(const char *link_id)
2033 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2037 *Set the endpoints for a route
2039 void routing_set_route(const char *src_id, const char *dst_id)
2041 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2045 * Store the route by calling parse_E_route_store_route
2047 void routing_store_route(void)
2049 parse_E_route_store_route();