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);
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(sg_platf_host_cbarg_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(sg_platf_router_cbarg_t router)
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,router->V_router_id, ROUTING_ASR_LEVEL),
216 "Reading a router, processing unit \"%s\" already exists",
217 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 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,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,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_lua(const char* router_id) {
240 s_sg_platf_router_cbarg_t router;
241 memset(&router,0,sizeof(router));
242 router.V_router_id = router_id;
243 router.V_router_coord = "";
244 return parse_S_router(&router);
248 * \brief Set the endponints for a route
250 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
252 if (src != NULL && dst != NULL && link_list != NULL)
253 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
257 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
258 "Some limits are null in the route between \"%s\" and \"%s\"",
260 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
264 * \brief Set the endpoints for a route from XML
266 static void parse_S_route_new_and_endpoints_XML(void)
268 parse_S_route_new_and_endpoints(A_surfxml_route_src,
269 A_surfxml_route_dst);
273 * \brief Set the endpoints for a route from lua
275 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
277 parse_S_route_new_and_endpoints(id_src, id_dst);
281 * \brief Set the endponints and gateways for a ASroute
283 static void parse_S_ASroute_new_and_endpoints(void)
285 if (src != NULL && dst != NULL && link_list != NULL)
286 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
287 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
288 src = A_surfxml_ASroute_src;
289 dst = A_surfxml_ASroute_dst;
290 gw_src = A_surfxml_ASroute_gw_src;
291 gw_dst = A_surfxml_ASroute_gw_dst;
292 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
293 || strlen(gw_dst) > 0,
294 "Some limits are null in the route between \"%s\" and \"%s\"",
296 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
300 * \brief Set the endponints for a bypassRoute
302 static void parse_S_bypassRoute_new_and_endpoints(void)
304 if (src != NULL && dst != NULL && link_list != NULL)
306 "Bypass Route between %s to %s can not be defined",
307 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
308 src = A_surfxml_bypassRoute_src;
309 dst = A_surfxml_bypassRoute_dst;
310 gw_src = A_surfxml_bypassRoute_gw_src;
311 gw_dst = A_surfxml_bypassRoute_gw_dst;
312 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
313 || strlen(gw_dst) > 0,
314 "Some limits are null in the route between \"%s\" and \"%s\"",
316 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
320 * \brief Set a new link on the actual list of link for a route or ASroute
322 static void parse_E_link_ctn_new_elem(const char *link_id)
325 val = xbt_strdup(link_id);
326 xbt_dynar_push(link_list, &val);
330 * \brief Set a new link on the actual list of link for a route or ASroute from XML
333 static void parse_E_link_ctn_new_elem_XML(void)
335 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
336 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
337 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
338 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
339 parse_E_link_ctn_new_elem(link_id);
342 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
343 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
344 parse_E_link_ctn_new_elem(link_id);
350 * \brief Set a new link on the actual list of link for a route or ASroute from lua
352 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
354 parse_E_link_ctn_new_elem(link_id);
358 * \brief Store the route by calling the set_route function of the current routing component
360 static void parse_E_route_store_route(void)
362 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
363 route->generic_route.link_list = link_list;
364 xbt_assert(current_routing->set_route,
365 "no defined method \"set_route\" in \"%s\"",
366 current_routing->name);
367 (*(current_routing->set_route)) (current_routing, src, dst, route);
374 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
376 static void parse_E_ASroute_store_route(void)
378 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
379 e_route->generic_route.link_list = link_list;
380 e_route->src_gateway = xbt_strdup(gw_src);
381 e_route->dst_gateway = xbt_strdup(gw_dst);
382 xbt_assert(current_routing->set_ASroute,
383 "no defined method \"set_ASroute\" in \"%s\"",
384 current_routing->name);
385 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
394 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
396 static void parse_E_bypassRoute_store_route(void)
398 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
399 e_route->generic_route.link_list = link_list;
400 e_route->src_gateway = xbt_strdup(gw_src);
401 e_route->dst_gateway = xbt_strdup(gw_dst);
402 xbt_assert(current_routing->set_bypassroute,
403 "no defined method \"set_bypassroute\" in \"%s\"",
404 current_routing->name);
405 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
415 * \brief Make a new routing component to the platform
417 * Add a new autonomous system to the platform. Any elements (such as host,
418 * router or sub-AS) added after this call and before the corresponding call
419 * to sg_platf_new_AS_close() will be added to this AS.
421 * Once this function was called, the configuration concerning the used
422 * models cannot be changed anymore.
424 * @param AS_id name of this autonomous system. Must be uniq in the platform
425 * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
427 void sg_platf_new_AS_open(const char *AS_id, const char *wanted_routing_type)
429 routing_component_t new_routing;
430 model_type_t model = NULL;
433 surf_parse_models_setup(); /* ensure that the models are created after the last <config> tag and before the first <AS>-like */
435 /* search the routing model */
436 for (cpt = 0; routing_models[cpt].name; cpt++)
437 if (!strcmp(wanted_routing_type, routing_models[cpt].name))
438 model = &routing_models[cpt];
439 /* if its not exist, error */
441 fprintf(stderr, "Routing model %s not found. Existing models:\n",
442 wanted_routing_type);
443 for (cpt = 0; routing_models[cpt].name; cpt++)
444 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
445 routing_models[cpt].desc);
449 /* make a new routing component */
450 new_routing = (routing_component_t) (*(model->create)) ();
451 new_routing->routing = model;
452 new_routing->hierarchy = SURF_ROUTING_NULL;
453 new_routing->name = xbt_strdup(AS_id);
454 new_routing->routing_sons = xbt_dict_new();
456 /* Hack for Vivaldi */
457 if(!strcmp(model->name,"Vivaldi"))
458 new_routing->get_latency = vivaldi_get_link_latency;
460 if (current_routing == NULL && global_routing->root == NULL) {
462 /* it is the first one */
463 new_routing->routing_father = NULL;
464 global_routing->root = new_routing;
466 } else if (current_routing != NULL && global_routing->root != NULL) {
468 xbt_assert(!xbt_dict_get_or_null
469 (current_routing->routing_sons, AS_id),
470 "The AS \"%s\" already exists", AS_id);
471 /* it is a part of the tree */
472 new_routing->routing_father = current_routing;
473 /* set the father behavior */
474 if (current_routing->hierarchy == SURF_ROUTING_NULL)
475 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
476 /* add to the sons dictionary */
477 xbt_dict_set(current_routing->routing_sons, AS_id,
478 (void *) new_routing, NULL);
479 /* add to the father element list */
480 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
481 /* unload the prev parse rules */
482 (*(current_routing->routing->unload)) ();
485 THROWF(arg_error, 0, "All defined components must be belong to a AS");
487 /* set the new parse rules */
488 (*(new_routing->routing->load)) ();
489 /* set the new current component of the tree */
490 current_routing = new_routing;
494 * \brief Specify that the current description of AS is finished
496 * Once you've declared all the content of your AS, you have to close
497 * it with this call. Your AS is not usable until you call this function.
499 * @fixme: this call is not as robust as wanted: bad things WILL happen
500 * if you call it twice for the same AS, or if you forget calling it, or
501 * even if you add stuff to a closed AS
504 void sg_platf_new_AS_close() {
506 if (current_routing == NULL) {
507 THROWF(arg_error, 0, "Close an AS, but none was under construction");
509 network_element_info_t info = NULL;
510 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
511 "The AS \"%s\" already exists",current_routing->name);
512 info = xbt_new0(s_network_element_info_t, 1);
513 info->rc_component = current_routing->routing_father;
514 info->rc_type = SURF_NETWORK_ELEMENT_AS;
515 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
517 (*(current_routing->routing->unload)) ();
518 (*(current_routing->routing->end)) ();
519 current_routing = current_routing->routing_father;
520 if (current_routing != NULL)
521 (*(current_routing->routing->load)) ();
525 /* Aux Business methods */
528 * \brief Get the AS name of the element
530 * \param name the host name
533 static char* elements_As_name(const char *name)
535 routing_component_t as_comp;
537 /* (1) find the as where the host is located */
538 as_comp = ((network_element_info_t)
539 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
540 return as_comp->name;
545 * \brief Get the AS father and the first elements of the chain
547 * \param src the source host name
548 * \param dst the destination host name
550 * Get the common father of the to processing units, and the first different
551 * father in the chain
553 static void elements_father(const char *src, const char *dst,
554 routing_component_t *res_father,
555 routing_component_t *res_src,
556 routing_component_t *res_dst)
558 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
559 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
560 routing_component_t src_as, dst_as;
561 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
562 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
565 routing_component_t current;
566 routing_component_t current_src;
567 routing_component_t current_dst;
568 routing_component_t father;
570 /* (1) find the as where the src and dst are located */
571 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
573 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
576 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
578 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
579 src_as = src_data->rc_component;
580 dst_as = dst_data->rc_component;
582 xbt_assert(src_as && dst_as,
583 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
585 /* (2) find the path to the root routing component */
586 for (current = src_as ; current != NULL ; current = current->routing_father) {
587 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
588 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
589 path_src[index_src++] = current;
591 for (current = dst_as ; current != NULL ; current = current->routing_father) {
592 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
593 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
594 path_dst[index_dst++] = current;
597 /* (3) find the common father */
599 current_src = path_src[--index_src];
600 current_dst = path_dst[--index_dst];
601 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
603 /* (4) they are not in the same routing component, make the path */
604 if (current_src == current_dst)
605 father = current_src;
607 father = path_src[index_src + 1];
609 /* (5) result generation */
610 *res_father = father; /* first the common father of src and dst */
611 *res_src = current_src; /* second the first different father of src */
612 *res_dst = current_dst; /* three the first different father of dst */
614 #undef ELEMENTS_FATHER_MAXDEPTH
617 /* Global Business methods */
620 * \brief Recursive function for get_route_latency
622 * \param src the source host name
623 * \param dst the destination host name
624 * \param *e_route the route where the links are stored
625 * \param *latency the latency, if needed
627 * This function is called by "get_route" and "get_latency". It allows to walk
628 * recursively through the routing components tree.
630 static void _get_route_latency(const char *src, const char *dst,
631 xbt_dynar_t *route, double *latency)
633 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
634 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
636 routing_component_t common_father;
637 routing_component_t src_father;
638 routing_component_t dst_father;
639 elements_father(src, dst, &common_father, &src_father, &dst_father);
641 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
643 route_extended_t e_route = NULL;
645 e_route = common_father->get_route(common_father, src, dst);
646 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
647 *route = e_route->generic_route.link_list;
650 *latency = common_father->get_latency(common_father, src, dst, e_route);
651 xbt_assert(*latency >= 0.0,
652 "latency error on route between \"%s\" and \"%s\"", src, dst);
655 xbt_free(e_route->src_gateway);
656 xbt_free(e_route->dst_gateway);
660 } else { /* SURF_ROUTING_RECURSIVE */
662 route_extended_t e_route_bypass = NULL;
663 if (common_father->get_bypass_route)
664 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
666 xbt_assert(!latency || !e_route_bypass,
667 "Bypass cannot work yet with get_latency");
669 route_extended_t e_route_cnt = e_route_bypass
671 : common_father->get_route(common_father,
672 src_father->name, dst_father->name);
674 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
675 src_father->name, dst_father->name);
677 xbt_assert((e_route_cnt->src_gateway == NULL) ==
678 (e_route_cnt->dst_gateway == NULL),
679 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
682 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
685 *latency = common_father->get_latency(common_father,
686 src_father->name, dst_father->name,
688 xbt_assert(*latency >= 0.0,
689 "latency error on route between \"%s\" and \"%s\"",
690 src_father->name, dst_father->name);
696 if (strcmp(src, e_route_cnt->src_gateway)) {
698 xbt_dynar_t route_src;
700 _get_route_latency(src, e_route_cnt->src_gateway,
701 (route ? &route_src : NULL),
702 (latency ? &latency_src : NULL));
704 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
705 src, e_route_cnt->src_gateway);
706 xbt_dynar_foreach(route_src, cpt, link) {
707 xbt_dynar_push(*route, &link);
709 xbt_dynar_free(&route_src);
712 xbt_assert(latency_src >= 0.0,
713 "latency error on route between \"%s\" and \"%s\"",
714 src, e_route_cnt->src_gateway);
715 *latency += latency_src;
720 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
721 xbt_dynar_push(*route, &link);
725 if (strcmp(e_route_cnt->dst_gateway, dst)) {
727 xbt_dynar_t route_dst;
729 _get_route_latency(e_route_cnt->dst_gateway, dst,
730 (route ? &route_dst : NULL),
731 (latency ? &latency_dst : NULL));
733 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
734 e_route_cnt->dst_gateway, dst);
735 xbt_dynar_foreach(route_dst, cpt, link) {
736 xbt_dynar_push(*route, &link);
738 xbt_dynar_free(&route_dst);
741 xbt_assert(latency_dst >= 0.0,
742 "latency error on route between \"%s\" and \"%s\"",
743 e_route_cnt->dst_gateway, dst);
744 *latency += latency_dst;
748 generic_free_extended_route(e_route_cnt);
753 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
755 static void get_route_latency(const char *src, const char *dst,
756 xbt_dynar_t *route, double *latency, int cleanup)
758 _get_route_latency(src, dst, route, latency);
759 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
760 xbt_assert(!latency || *latency >= 0.0,
761 "latency error on route between \"%s\" and \"%s\"", src, dst);
763 xbt_dynar_free(&global_routing->last_route);
764 global_routing->last_route = cleanup ? *route : NULL;
769 * \brief Generic method: find a route between hosts
771 * \param src the source host name
772 * \param dst the destination host name
774 * walk through the routing components tree and find a route between hosts
775 * by calling the differents "get_route" functions in each routing component.
776 * No need to free the returned dynar. It will be freed at the next call.
778 static xbt_dynar_t get_route(const char *src, const char *dst)
780 xbt_dynar_t route = NULL;
781 get_route_latency(src, dst, &route, NULL, 1);
786 * \brief Generic method: find a route between hosts
788 * \param src the source host name
789 * \param dst the destination host name
791 * same as get_route, but return NULL if any exception is raised.
793 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
795 xbt_dynar_t route = NULL;
798 get_route_latency(src, dst, &route, NULL, 1);
800 xbt_ex_free(exception);
807 * \brief Generic method: find a route between hosts
809 * \param src the source host name
810 * \param dst the destination host name
812 * walk through the routing components tree and find a route between hosts
813 * by calling the differents "get_route" functions in each routing component.
814 * Leaves the caller the responsability to clean the returned dynar.
816 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
818 xbt_dynar_t route = NULL;
819 get_route_latency(src, dst, &route, NULL, 0);
824 static double get_latency(const char *src, const char *dst)
826 double latency = -1.0;
827 get_route_latency(src, dst, NULL, &latency, 0);
831 static int surf_parse_models_setup_already_called=0;
832 /* Call the last initialization functions, that must be called after the
833 * <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
835 void surf_parse_models_setup()
837 if (surf_parse_models_setup_already_called)
839 surf_parse_models_setup_already_called=1;
840 routing_parse_Erandom();
841 surf_config_models_setup();
846 * \brief Recursive function for finalize
848 * \param rc the source host name
850 * This fuction is call by "finalize". It allow to finalize the
851 * AS or routing components. It delete all the structures.
853 static void _finalize(routing_component_t rc)
856 xbt_dict_cursor_t cursor = NULL;
858 routing_component_t elem;
859 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
862 xbt_dict_t tmp_sons = rc->routing_sons;
863 char *tmp_name = rc->name;
864 xbt_dict_free(&tmp_sons);
866 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
867 current_routing->name);
868 (*(rc->finalize)) (rc);
873 * \brief Generic method: delete all the routing structures
875 * walk through the routing components tree and delete the structures
876 * by calling the differents "finalize" functions in each routing component
878 static void finalize(void)
880 /* delete recursibly all the tree */
881 _finalize(global_routing->root);
882 /* delete last_route */
883 xbt_dynar_free(&(global_routing->last_route));
884 /* delete global routing structure */
885 xbt_free(global_routing);
886 /* make sure that we will reinit the models while loading the platf once reinited -- HACK but there is no proper surf_routing_init() */
887 surf_parse_models_setup_already_called = 0;
890 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
892 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
894 //adding my one link routes
897 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
899 xbt_dynar_foreach(onelink_mine, cpt, link) {
900 xbt_dynar_push(ret, &link);
905 xbt_dict_cursor_t cursor = NULL;
906 routing_component_t rc_child;
907 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
908 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
910 xbt_dynar_foreach(onelink_child, cpt, link) {
911 xbt_dynar_push(ret, &link);
918 static xbt_dynar_t get_onelink_routes(void)
920 return recursive_get_onelink_routes(global_routing->root);
923 e_surf_network_element_type_t get_network_element_type(const char
926 network_element_info_t rc = NULL;
928 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
929 if(rc) return rc->rc_type;
931 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
932 if(rc) return rc->rc_type;
934 return SURF_NETWORK_ELEMENT_NULL;
938 * \brief Generic method: create the global routing schema
940 * Make a global routing structure and set all the parsing functions.
942 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
944 /* config the uniq global routing */
945 global_routing = xbt_new0(s_routing_global_t, 1);
946 global_routing->root = NULL;
947 global_routing->get_route = get_route;
948 global_routing->get_route_or_null = get_route_or_null;
949 global_routing->get_latency = get_latency;
950 global_routing->get_route_no_cleanup = get_route_no_cleanup;
951 global_routing->get_onelink_routes = get_onelink_routes;
952 global_routing->get_route_latency = get_route_latency;
953 global_routing->get_network_element_type = get_network_element_type;
954 global_routing->finalize = finalize;
955 global_routing->loopback = loopback;
956 global_routing->size_of_link = size_of_links;
957 global_routing->last_route = NULL;
958 get_link_latency = get_link_latency_fun;
959 /* no current routing at moment */
960 current_routing = NULL;
962 /* parse generic elements */
963 sg_platf_host_add_cb(parse_S_host_XML);
964 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
965 sg_platf_router_add_cb(parse_S_router);
967 surfxml_add_callback(STag_surfxml_route_cb_list,
968 &parse_S_route_new_and_endpoints_XML);
969 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
970 &parse_S_ASroute_new_and_endpoints);
971 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
972 &parse_S_bypassRoute_new_and_endpoints);
974 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
975 &parse_E_link_ctn_new_elem_XML);
977 surfxml_add_callback(ETag_surfxml_route_cb_list,
978 &parse_E_route_store_route);
979 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
980 &parse_E_ASroute_store_route);
981 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
982 &parse_E_bypassRoute_store_route);
984 surfxml_add_callback(STag_surfxml_cluster_cb_list,
985 &routing_parse_Scluster);
987 surfxml_add_callback(STag_surfxml_peer_cb_list,
988 &routing_parse_Speer);
990 surfxml_add_callback(ETag_surfxml_platform_cb_list,
991 &clean_routing_after_parse);
994 instr_routing_define_callbacks();
998 void surf_parse_add_callback_config(void)
1000 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1001 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1004 /* ************************************************** */
1005 /* ********** PATERN FOR NEW ROUTING **************** */
1007 /* The minimal configuration of a new routing model need the next functions,
1008 * also you need to set at the start of the file, the new model in the model
1009 * list. Remember keep the null ending of the list.
1011 /*** Routing model structure ***/
1013 // s_routing_component_t generic_routing;
1014 // /* things that your routing model need */
1015 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1017 /*** Parse routing model functions ***/
1018 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1019 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1020 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1021 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1022 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1024 /*** Business methods ***/
1025 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1026 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1027 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1029 /*** Creation routing model functions ***/
1030 // static void* model_NEW_create(void) {
1031 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1032 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1033 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1034 // new_component->generic_routing.set_route = model_NEW_set_route;
1035 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1036 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1037 // new_component->generic_routing.get_route = NEW_get_route;
1038 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1039 // new_component->generic_routing.finalize = NEW_finalize;
1040 // /* initialization of internal structures */
1041 // return new_component;
1042 // } /* mandatory */
1043 // static void model_NEW_load(void) {} /* mandatory */
1044 // static void model_NEW_unload(void) {} /* mandatory */
1045 // static void model_NEW_end(void) {} /* mandatory */
1047 /* ************************************************************************** */
1048 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1050 void generic_set_processing_unit(routing_component_t rc,
1053 XBT_DEBUG("Load process unit \"%s\"", name);
1054 int *id = xbt_new0(int, 1);
1055 xbt_dict_t _to_index;
1056 _to_index = current_routing->to_index;
1057 *id = xbt_dict_length(_to_index);
1058 xbt_dict_set(_to_index, name, id, xbt_free);
1061 void generic_set_autonomous_system(routing_component_t rc,
1064 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1065 int *id = xbt_new0(int, 1);
1066 xbt_dict_t _to_index;
1067 _to_index = current_routing->to_index;
1068 *id = xbt_dict_length(_to_index);
1069 xbt_dict_set(_to_index, name, id, xbt_free);
1072 int surf_pointer_resource_cmp(const void *a, const void *b)
1077 int surf_link_resource_cmp(const void *a, const void *b)
1079 return !!memcmp(a,b,global_routing->size_of_link);
1082 void generic_set_bypassroute(routing_component_t rc,
1083 const char *src, const char *dst,
1084 route_extended_t e_route)
1086 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1087 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1090 route_name = bprintf("%s#%s", src, dst);
1091 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1092 "Invalid count of links, must be greater than zero (%s,%s)",
1094 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1095 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1096 src, e_route->src_gateway, dst, e_route->dst_gateway);
1098 route_extended_t new_e_route =
1099 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1100 xbt_dynar_free(&(e_route->generic_route.link_list));
1103 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1104 (void (*)(void *)) generic_free_extended_route);
1105 xbt_free(route_name);
1108 /* ************************************************************************** */
1109 /* *********************** GENERIC BUSINESS METHODS ************************* */
1111 double generic_get_link_latency(routing_component_t rc,
1112 const char *src, const char *dst,
1113 route_extended_t route)
1115 int need_to_clean = route?0:1;
1118 double latency = 0.0;
1120 route = route?route:rc->get_route(rc,src,dst);
1122 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1123 latency += get_link_latency(link);
1125 if(need_to_clean) generic_free_extended_route(route);
1129 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1131 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1134 route_extended_t generic_get_bypassroute(routing_component_t rc,
1138 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1139 routing_component_t src_as, dst_as;
1140 int index_src, index_dst;
1141 xbt_dynar_t path_src = NULL;
1142 xbt_dynar_t path_dst = NULL;
1143 routing_component_t current = NULL;
1144 routing_component_t *current_src = NULL;
1145 routing_component_t *current_dst = NULL;
1147 /* (1) find the as where the src and dst are located */
1148 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1149 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1150 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1151 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1153 if(src_data == NULL || dst_data == NULL)
1154 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1155 src, dst, rc->name);
1157 src_as = ((network_element_info_t)src_data)->rc_component;
1158 dst_as = ((network_element_info_t)dst_data)->rc_component;
1160 /* (2) find the path to the root routing component */
1161 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1163 while (current != NULL) {
1164 xbt_dynar_push(path_src, ¤t);
1165 current = current->routing_father;
1167 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1169 while (current != NULL) {
1170 xbt_dynar_push(path_dst, ¤t);
1171 current = current->routing_father;
1174 /* (3) find the common father */
1175 index_src = path_src->used - 1;
1176 index_dst = path_dst->used - 1;
1177 current_src = xbt_dynar_get_ptr(path_src, index_src);
1178 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1179 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1180 xbt_dynar_pop_ptr(path_src);
1181 xbt_dynar_pop_ptr(path_dst);
1184 current_src = xbt_dynar_get_ptr(path_src, index_src);
1185 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1188 int max_index_src = path_src->used - 1;
1189 int max_index_dst = path_dst->used - 1;
1191 int max_index = max(max_index_src, max_index_dst);
1194 route_extended_t e_route_bypass = NULL;
1196 for (max = 0; max <= max_index; max++) {
1197 for (i = 0; i < max; i++) {
1198 if (i <= max_index_src && max <= max_index_dst) {
1199 char *route_name = bprintf("%s#%s",
1200 (*(routing_component_t *)
1202 (path_src, i)))->name,
1203 (*(routing_component_t *)
1205 (path_dst, max)))->name);
1207 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1208 xbt_free(route_name);
1212 if (max <= max_index_src && i <= max_index_dst) {
1213 char *route_name = bprintf("%s#%s",
1214 (*(routing_component_t *)
1216 (path_src, max)))->name,
1217 (*(routing_component_t *)
1219 (path_dst, i)))->name);
1221 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1222 xbt_free(route_name);
1231 if (max <= max_index_src && max <= max_index_dst) {
1232 char *route_name = bprintf("%s#%s",
1233 (*(routing_component_t *)
1235 (path_src, max)))->name,
1236 (*(routing_component_t *)
1238 (path_dst, max)))->name);
1239 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1240 xbt_free(route_name);
1246 xbt_dynar_free(&path_src);
1247 xbt_dynar_free(&path_dst);
1249 route_extended_t new_e_route = NULL;
1251 if (e_route_bypass) {
1253 unsigned int cpt = 0;
1254 new_e_route = xbt_new0(s_route_extended_t, 1);
1255 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1256 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1257 new_e_route->generic_route.link_list =
1258 xbt_dynar_new(global_routing->size_of_link, NULL);
1259 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1260 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1267 /* ************************************************************************** */
1268 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1271 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1272 void *data, int order)
1278 xbt_dynar_t links = NULL, links_id = NULL;
1280 new_route = xbt_new0(s_route_t, 1);
1281 new_route->link_list =
1282 xbt_dynar_new(global_routing->size_of_link, NULL);
1284 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1285 "the hierarchy type is not SURF_ROUTING_BASE");
1287 links = ((route_t) data)->link_list;
1290 links_id = new_route->link_list;
1292 xbt_dynar_foreach(links, cpt, link_name) {
1295 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1298 xbt_dynar_push(links_id, &link);
1300 xbt_dynar_unshift(links_id, &link);
1302 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1309 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1310 void *data, int order)
1314 route_extended_t e_route, new_e_route;
1317 xbt_dynar_t links = NULL, links_id = NULL;
1319 new_e_route = xbt_new0(s_route_extended_t, 1);
1320 new_e_route->generic_route.link_list =
1321 xbt_dynar_new(global_routing->size_of_link, NULL);
1322 new_e_route->src_gateway = NULL;
1323 new_e_route->dst_gateway = NULL;
1325 xbt_assert(hierarchy == SURF_ROUTING_BASE
1326 || hierarchy == SURF_ROUTING_RECURSIVE,
1327 "the hierarchy type is not defined");
1329 if (hierarchy == SURF_ROUTING_BASE) {
1331 route = (route_t) data;
1332 links = route->link_list;
1334 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1336 e_route = (route_extended_t) data;
1337 xbt_assert(e_route->src_gateway
1338 && e_route->dst_gateway, "bad gateway, is null");
1339 links = e_route->generic_route.link_list;
1341 /* remeber not erase the gateway names */
1342 new_e_route->src_gateway = strdup(e_route->src_gateway);
1343 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1346 links_id = new_e_route->generic_route.link_list;
1348 xbt_dynar_foreach(links, cpt, link_name) {
1351 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1354 xbt_dynar_push(links_id, &link);
1356 xbt_dynar_unshift(links_id, &link);
1358 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1364 void generic_free_route(route_t route)
1367 xbt_dynar_free(&(route->link_list));
1372 void generic_free_extended_route(route_extended_t e_route)
1375 xbt_dynar_free(&(e_route->generic_route.link_list));
1376 if (e_route->src_gateway)
1377 xbt_free(e_route->src_gateway);
1378 if (e_route->dst_gateway)
1379 xbt_free(e_route->dst_gateway);
1384 static routing_component_t generic_as_exist(routing_component_t find_from,
1385 routing_component_t to_find)
1387 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1388 xbt_dict_cursor_t cursor = NULL;
1391 routing_component_t elem;
1392 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1393 if (to_find == elem || generic_as_exist(elem, to_find)) {
1404 generic_autonomous_system_exist(routing_component_t rc, char *element)
1406 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1407 routing_component_t element_as, result, elem;
1408 xbt_dict_cursor_t cursor = NULL;
1410 element_as = ((network_element_info_t)
1411 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1412 result = ((routing_component_t) - 1);
1413 if (element_as != rc)
1414 result = generic_as_exist(rc, element_as);
1418 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1419 found = !strcmp(elem->name, element);
1430 generic_processing_units_exist(routing_component_t rc, char *element)
1432 routing_component_t element_as;
1433 element_as = ((network_element_info_t)
1434 xbt_lib_get_or_null(host_lib,
1435 element, ROUTING_HOST_LEVEL))->rc_component;
1436 if (element_as == rc)
1438 return generic_as_exist(rc, element_as);
1441 void generic_src_dst_check(routing_component_t rc, const char *src,
1445 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1446 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1447 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1448 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1450 if(src_data == NULL || dst_data == NULL)
1451 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1452 src, dst, rc->name);
1454 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1455 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1457 if(src_as != dst_as)
1458 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1459 src, src_as->name, dst, dst_as->name);
1461 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1462 src,dst,src_as->name, dst_as->name,rc->name);
1465 void routing_parse_Scluster(void)
1467 if(!cluster_host_link)
1468 cluster_host_link = xbt_dict_new();
1470 static int AX_ptr = 0;
1471 char *host_id, *groups, *link_id = NULL;
1473 s_sg_platf_host_cbarg_t host;
1475 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1476 || strcmp(struct_cluster->V_cluster_state_file,"") )
1478 if(xbt_dict_size(patterns)==0)
1479 patterns = xbt_dict_new();
1480 xbt_dict_set(patterns,"id",struct_cluster->V_cluster_id,NULL);
1481 xbt_dict_set(patterns,"prefix",struct_cluster->V_cluster_prefix,NULL);
1482 xbt_dict_set(patterns,"suffix",struct_cluster->V_cluster_suffix,NULL);
1487 xbt_dynar_t radical_elements;
1488 xbt_dynar_t radical_ends;
1490 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1491 static unsigned int surfxml_buffer_stack_stack[1024];
1493 surfxml_buffer_stack_stack[0] = 0;
1494 surfxml_bufferstack_push(1);
1496 SURFXML_BUFFER_SET(AS_id, struct_cluster->V_cluster_id);
1497 SURFXML_BUFFER_SET(AS_routing, "Cluster");
1498 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", struct_cluster->V_cluster_id);
1499 SURFXML_START_TAG(AS);
1502 radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ",");
1503 xbt_dynar_foreach(radical_elements, iter, groups) {
1504 memset(&host,0,sizeof(host));
1506 radical_ends = xbt_str_split(groups, "-");
1507 switch (xbt_dynar_length(radical_ends)) {
1509 start=surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1510 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, start, struct_cluster->V_cluster_suffix);
1511 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start);
1513 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1514 host.V_host_id = host_id;
1515 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1516 xbt_dict_set(patterns, "radical", bprintf("%d", start), 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 sg_platf_new_host(&host);
1545 XBT_DEBUG("</host>");
1547 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1548 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1549 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1550 if(struct_cluster->V_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);
1580 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX){
1581 char* tmp_link = bprintf("%s_UP",link_id);
1582 info->link_up = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1584 tmp_link = bprintf("%s_DOWN",link_id);
1585 info->link_down = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1589 info->link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
1590 info->link_down = info->link_up;
1592 xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
1600 start=surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1601 end= surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
1602 for (i = start; i <= end; i++) {
1603 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1604 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1606 A_surfxml_host_state = A_surfxml_host_state_ON;
1608 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1609 host.V_host_id = host_id;
1610 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1611 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1612 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1613 xbt_str_varsubst(tmp_availability_file,patterns);
1614 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1615 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1616 xbt_free(tmp_availability_file);
1620 XBT_DEBUG("\tavailability_file=\"\"");
1622 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1623 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1624 xbt_str_varsubst(tmp_state_file,patterns);
1625 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1626 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1627 xbt_free(tmp_state_file);
1631 XBT_DEBUG("\tstate_file=\"\"");
1634 host.V_host_power_peak = struct_cluster->S_cluster_power;
1635 host.V_host_power_scale = 1.0;
1636 host.V_host_core = struct_cluster->S_cluster_core;
1637 host.V_host_state_initial = SURF_RESOURCE_ON;
1638 host.V_host_coord = "";
1639 sg_platf_new_host(&host);
1640 XBT_DEBUG("</host>");
1642 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1643 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1644 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1645 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1646 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1648 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1650 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1651 struct_lnk->V_link_id = xbt_strdup(link_id);
1652 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1653 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1654 struct_lnk->V_link_bandwidth_file = NULL;
1655 struct_lnk->V_link_latency_file = NULL;
1656 struct_lnk->V_link_state_file = NULL;
1657 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1658 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1660 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1661 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1664 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1665 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1666 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1667 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1671 ETag_surfxml_host();
1672 ETag_surfxml_link();
1674 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1675 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX){
1676 char* tmp_link = bprintf("%s_UP",link_id);
1677 info->link_up = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1679 tmp_link = bprintf("%s_DOWN",link_id);
1680 info->link_down = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1684 info->link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
1685 info->link_down = info->link_up;
1687 xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
1695 XBT_DEBUG("Malformed radical");
1699 xbt_dynar_free(&radical_ends);
1701 xbt_dynar_free(&radical_elements);
1705 XBT_DEBUG("<router id=\"%s\"/>", struct_cluster->S_cluster_router_id);
1706 SURFXML_BUFFER_SET(router_id, struct_cluster->S_cluster_router_id);
1707 SURFXML_BUFFER_SET(router_coordinates, "");
1708 SURFXML_START_TAG(router);
1709 SURFXML_END_TAG(router);
1712 if( (struct_cluster->S_cluster_bb_bw!= 0) && (struct_cluster->S_cluster_bb_lat!=0) ){
1713 char *link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1714 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,struct_cluster->S_cluster_bb_bw, struct_cluster->S_cluster_bb_lat);
1716 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1717 if(AX_surfxml_cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1718 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1720 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1721 struct_lnk->V_link_id = xbt_strdup(link_backbone);
1722 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bb_bw;
1723 struct_lnk->V_link_latency = struct_cluster->S_cluster_bb_lat;
1724 struct_lnk->V_link_bandwidth_file = NULL;
1725 struct_lnk->V_link_latency_file = NULL;
1726 struct_lnk->V_link_state_file = NULL;
1727 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1728 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1730 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1731 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1733 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1736 ETag_surfxml_link();
1738 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1739 info->link_up = xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL);
1740 info->link_down = info->link_up;
1741 xbt_dict_set(cluster_host_link,struct_cluster->V_cluster_id,info,xbt_free);
1742 free(link_backbone);
1747 char *new_suffix = xbt_strdup("");
1749 radical_elements = xbt_str_split(struct_cluster->V_cluster_suffix, ".");
1750 xbt_dynar_foreach(radical_elements, iter, groups) {
1751 if (strcmp(groups, "")) {
1752 char *old_suffix = new_suffix;
1753 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1758 xbt_dynar_free(&radical_elements);
1759 xbt_free(new_suffix);
1761 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1762 || strcmp(struct_cluster->V_cluster_state_file,"") )
1763 xbt_dict_free(&patterns);
1766 SURFXML_END_TAG(AS);
1769 surfxml_bufferstack_pop(1);
1772 * This function take a string and replace parameters from patterns dict.
1773 * It returns the new value.
1775 static char* replace_random_parameter(char * string)
1777 char *test_string = NULL;
1779 if(xbt_dict_size(random_value)==0)
1782 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1783 test_string = bprintf("${%s}", string);
1784 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1786 if (strcmp(test_string,"")) { //if not empty, keep this value.
1788 string = test_string;
1789 } //In other case take old value (without ${})
1795 static void clean_routing_after_parse(void)
1797 xbt_dict_free(&random_value);
1798 xbt_dict_free(&patterns);
1801 static void routing_parse_Speer(void)
1803 static int AX_ptr = 0;
1804 char *host_id = NULL;
1805 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1807 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1808 static unsigned int surfxml_buffer_stack_stack[1024];
1810 surfxml_buffer_stack_stack[0] = 0;
1812 surfxml_bufferstack_push(1);
1814 SURFXML_BUFFER_SET(AS_id, struct_peer->V_peer_id);
1816 SURFXML_BUFFER_SET(AS_routing, "Full");
1817 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->V_peer_id);
1819 SURFXML_START_TAG(AS);
1822 host_id = bprintf("peer_%s", struct_peer->V_peer_id);
1823 router_id = bprintf("router_%s", struct_peer->V_peer_id);
1824 link_id_up = bprintf("link_%s_up", struct_peer->V_peer_id);
1825 link_id_down = bprintf("link_%s_down", struct_peer->V_peer_id);
1827 link_router = bprintf("%s_link_router", struct_peer->V_peer_id);
1828 link_backbone = bprintf("%s_backbone", struct_peer->V_peer_id);
1830 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, struct_peer->V_peer_power);
1831 A_surfxml_host_state = A_surfxml_host_state_ON;
1832 SURFXML_BUFFER_SET(host_id, host_id);
1833 SURFXML_BUFFER_SET(host_power, struct_peer->V_peer_power);
1834 SURFXML_BUFFER_SET(host_availability, "1.0");
1835 SURFXML_BUFFER_SET(host_availability_file, struct_peer->V_peer_availability_trace);
1836 SURFXML_BUFFER_SET(host_state_file, struct_peer->V_peer_state_trace);
1837 SURFXML_BUFFER_SET(host_coordinates, "");
1838 SURFXML_BUFFER_SET(host_core, "1.0");
1839 SURFXML_START_TAG(host);
1840 SURFXML_END_TAG(host);
1842 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->V_peer_coord);
1843 SURFXML_BUFFER_SET(router_id, router_id);
1844 SURFXML_BUFFER_SET(router_coordinates, struct_peer->V_peer_coord);
1845 SURFXML_START_TAG(router);
1846 SURFXML_END_TAG(router);
1848 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, struct_peer->V_peer_bw_in, struct_peer->V_peer_lat);
1849 A_surfxml_link_state = A_surfxml_link_state_ON;
1850 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1851 SURFXML_BUFFER_SET(link_id, link_id_up);
1852 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_in);
1853 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1854 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1855 SURFXML_BUFFER_SET(link_latency_file, "");
1856 SURFXML_BUFFER_SET(link_state_file, "");
1857 SURFXML_START_TAG(link);
1858 SURFXML_END_TAG(link);
1860 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, struct_peer->V_peer_bw_out, struct_peer->V_peer_lat);
1861 A_surfxml_link_state = A_surfxml_link_state_ON;
1862 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1863 SURFXML_BUFFER_SET(link_id, link_id_down);
1864 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_out);
1865 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1866 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1867 SURFXML_BUFFER_SET(link_latency_file, "");
1868 SURFXML_BUFFER_SET(link_state_file, "");
1869 SURFXML_START_TAG(link);
1870 SURFXML_END_TAG(link);
1875 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1876 XBT_DEBUG("symmetrical=\"NO\">");
1877 SURFXML_BUFFER_SET(route_src, host_id);
1878 SURFXML_BUFFER_SET(route_dst, router_id);
1879 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1880 SURFXML_START_TAG(route);
1882 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1883 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1884 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1885 SURFXML_START_TAG(link_ctn);
1886 SURFXML_END_TAG(link_ctn);
1888 XBT_DEBUG("</route>");
1889 SURFXML_END_TAG(route);
1892 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1893 XBT_DEBUG("symmetrical=\"NO\">");
1894 SURFXML_BUFFER_SET(route_src, router_id);
1895 SURFXML_BUFFER_SET(route_dst, host_id);
1896 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1897 SURFXML_START_TAG(route);
1899 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
1900 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
1901 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1902 SURFXML_START_TAG(link_ctn);
1903 SURFXML_END_TAG(link_ctn);
1905 XBT_DEBUG("</route>");
1906 SURFXML_END_TAG(route);
1909 SURFXML_END_TAG(AS);
1912 //xbt_dynar_free(&tab_elements_num);
1916 free(link_backbone);
1919 surfxml_bufferstack_pop(1);
1922 static void routing_parse_Srandom(void)
1924 double mean, std, min, max, seed;
1925 char *random_id = A_surfxml_random_id;
1926 char *random_radical = A_surfxml_random_radical;
1927 char *rd_name = NULL;
1929 mean = surf_parse_get_double(A_surfxml_random_mean);
1930 std = surf_parse_get_double(A_surfxml_random_std_deviation);
1931 min = surf_parse_get_double(A_surfxml_random_min);
1932 max = surf_parse_get_double(A_surfxml_random_max);
1933 seed = surf_parse_get_double(A_surfxml_random_seed);
1937 random_data_t random = xbt_new0(s_random_data_t, 1);
1940 xbt_dynar_t radical_elements;
1944 xbt_dynar_t radical_ends;
1946 random->generator = A_surfxml_random_generator;
1947 random->seed = seed;
1951 /* Check user stupidities */
1953 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
1955 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
1958 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
1961 /* normalize the mean and standard deviation before storing */
1962 random->mean = (mean - min) / (max - min);
1963 random->std = std / (max - min);
1965 if (random->mean * (1 - random->mean) < random->std * random->std)
1966 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
1967 random->mean, random->std);
1969 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
1979 if(xbt_dict_size(random_value)==0)
1980 random_value = xbt_dict_new();
1982 if(!strcmp(random_radical,""))
1984 res = random_generate(random);
1985 rd_value = bprintf("%f",res);
1986 xbt_dict_set(random_value, random_id, rd_value, free);
1990 radical_elements = xbt_str_split(random_radical, ",");
1991 xbt_dynar_foreach(radical_elements, iter, groups) {
1992 radical_ends = xbt_str_split(groups, "-");
1993 switch (xbt_dynar_length(radical_ends)) {
1995 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
1996 res = random_generate(random);
1997 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
1998 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2003 start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
2004 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
2005 for (i = start; i <= end; i++) {
2006 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2007 res = random_generate(random);
2008 tmpbuf = bprintf("%s%d",random_id,i);
2009 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2014 XBT_INFO("Malformed radical");
2017 res = random_generate(random);
2018 rd_name = bprintf("%s_router",random_id);
2019 rd_value = bprintf("%f",res);
2020 xbt_dict_set(random_value, rd_name, rd_value, free);
2022 xbt_dynar_free(&radical_ends);
2025 xbt_dynar_free(&radical_elements);
2029 static void routing_parse_Erandom(void)
2031 /*xbt_dict_cursor_t cursor = NULL;
2035 xbt_dict_foreach(random_value, cursor, key, elem) {
2036 XBT_DEBUG("%s = %s",key,elem);
2042 * New methods to init the routing model component from the lua script
2047 * add a host to the network element list
2050 void routing_add_host(const char *host_id)
2052 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2056 * Set a new link on the actual list of link for a route or ASroute
2058 void routing_add_link(const char *link_id)
2060 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2064 *Set the endpoints for a route
2066 void routing_set_route(const char *src_id, const char *dst_id)
2068 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2072 * Store the route by calling parse_E_route_store_route
2074 void routing_store_route(void)
2076 parse_E_route_store_route();