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);
1466 static void parse_create_host_link(int i)
1468 char *host_id, *link_id = NULL;
1469 s_sg_platf_host_cbarg_t host;
1470 memset(&host,0,sizeof(host));
1472 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1473 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1475 A_surfxml_host_state = A_surfxml_host_state_ON;
1477 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1478 host.V_host_id = xbt_strdup(host_id);
1479 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1480 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1481 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1482 xbt_str_varsubst(tmp_availability_file,patterns);
1483 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1484 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1485 xbt_free(tmp_availability_file);
1489 XBT_DEBUG("\tavailability_file=\"\"");
1491 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1492 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1493 xbt_str_varsubst(tmp_state_file,patterns);
1494 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1495 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1496 xbt_free(tmp_state_file);
1500 XBT_DEBUG("\tstate_file=\"\"");
1503 host.V_host_power_peak = struct_cluster->S_cluster_power;
1504 host.V_host_power_scale = 1.0;
1505 host.V_host_core = struct_cluster->S_cluster_core;
1506 host.V_host_state_initial = SURF_RESOURCE_ON;
1507 host.V_host_coord = "";
1508 sg_platf_new_host(&host);
1509 XBT_DEBUG("</host>");
1511 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1512 if(AX_surfxml_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1513 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1514 if(AX_surfxml_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1515 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1517 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1519 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1520 struct_lnk->V_link_id = xbt_strdup(link_id);
1521 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1522 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1523 struct_lnk->V_link_bandwidth_file = NULL;
1524 struct_lnk->V_link_latency_file = NULL;
1525 struct_lnk->V_link_state_file = NULL;
1526 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1527 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1529 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1530 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1533 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1534 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1535 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1536 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1540 ETag_surfxml_host();
1541 ETag_surfxml_link();
1543 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1545 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX){
1546 char* tmp_link = bprintf("%s_UP",link_id);
1547 info->link_up = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1549 tmp_link = bprintf("%s_DOWN",link_id);
1550 info->link_down = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1554 info->link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
1555 info->link_down = info->link_up;
1557 xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
1562 void routing_parse_Scluster(void)
1564 if(!cluster_host_link)
1565 cluster_host_link = xbt_dict_new();
1567 static int AX_ptr = 0;
1568 char *host_id, *groups, *link_id = NULL;
1570 s_sg_platf_host_cbarg_t host;
1572 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1573 || strcmp(struct_cluster->V_cluster_state_file,"") )
1575 if(xbt_dict_size(patterns)==0)
1576 patterns = xbt_dict_new();
1577 xbt_dict_set(patterns,"id",struct_cluster->V_cluster_id,NULL);
1578 xbt_dict_set(patterns,"prefix",struct_cluster->V_cluster_prefix,NULL);
1579 xbt_dict_set(patterns,"suffix",struct_cluster->V_cluster_suffix,NULL);
1584 xbt_dynar_t radical_elements;
1585 xbt_dynar_t radical_ends;
1587 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1588 static unsigned int surfxml_buffer_stack_stack[1024];
1590 surfxml_buffer_stack_stack[0] = 0;
1591 surfxml_bufferstack_push(1);
1593 SURFXML_BUFFER_SET(AS_id, struct_cluster->V_cluster_id);
1594 SURFXML_BUFFER_SET(AS_routing, "Cluster");
1595 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", struct_cluster->V_cluster_id);
1596 SURFXML_START_TAG(AS);
1599 radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ",");
1600 xbt_dynar_foreach(radical_elements, iter, groups) {
1601 memset(&host,0,sizeof(host));
1603 radical_ends = xbt_str_split(groups, "-");
1604 switch (xbt_dynar_length(radical_ends)) {
1606 start=surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1607 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, start, struct_cluster->V_cluster_suffix);
1608 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start);
1610 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1611 host.V_host_id = host_id;
1612 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1613 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1614 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1615 xbt_str_varsubst(tmp_availability_file,patterns);
1616 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1617 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1618 xbt_free(tmp_availability_file);
1622 XBT_DEBUG("\tavailability_file=\"\"");
1624 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1625 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1626 xbt_str_varsubst(tmp_state_file,patterns);
1627 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1628 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1629 xbt_free(tmp_state_file);
1633 XBT_DEBUG("\tstate_file=\"\"");
1636 host.V_host_power_peak = struct_cluster->S_cluster_power;
1637 host.V_host_power_scale = 1.0;
1638 host.V_host_core = struct_cluster->S_cluster_core;
1639 host.V_host_state_initial = SURF_RESOURCE_ON;
1640 host.V_host_coord = "";
1641 sg_platf_new_host(&host);
1642 XBT_DEBUG("</host>");
1644 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1645 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1646 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1647 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1648 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1650 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1652 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1653 struct_lnk->V_link_id = link_id;
1654 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1655 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1656 struct_lnk->V_link_bandwidth_file = NULL;
1657 struct_lnk->V_link_latency_file = NULL;
1658 struct_lnk->V_link_state_file = NULL;
1659 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1660 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1662 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1663 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1666 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1667 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1668 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1669 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1673 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1674 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1675 ETag_surfxml_host();
1676 ETag_surfxml_link();
1682 start=surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1683 end= surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
1684 for (i = start; i <= end; i++) {
1685 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1686 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1688 A_surfxml_host_state = A_surfxml_host_state_ON;
1690 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1691 host.V_host_id = host_id;
1692 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1693 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1694 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1695 xbt_str_varsubst(tmp_availability_file,patterns);
1696 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1697 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1698 xbt_free(tmp_availability_file);
1702 XBT_DEBUG("\tavailability_file=\"\"");
1704 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1705 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1706 xbt_str_varsubst(tmp_state_file,patterns);
1707 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1708 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1709 xbt_free(tmp_state_file);
1713 XBT_DEBUG("\tstate_file=\"\"");
1716 host.V_host_power_peak = struct_cluster->S_cluster_power;
1717 host.V_host_power_scale = 1.0;
1718 host.V_host_core = struct_cluster->S_cluster_core;
1719 host.V_host_state_initial = SURF_RESOURCE_ON;
1720 host.V_host_coord = "";
1721 sg_platf_new_host(&host);
1722 XBT_DEBUG("</host>");
1724 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1725 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1726 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1727 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1728 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1730 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1732 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1733 struct_lnk->V_link_id = link_id;
1734 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1735 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1736 struct_lnk->V_link_bandwidth_file = NULL;
1737 struct_lnk->V_link_latency_file = NULL;
1738 struct_lnk->V_link_state_file = NULL;
1739 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1740 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1742 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1743 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1746 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1747 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1748 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1749 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1753 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1754 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1756 ETag_surfxml_host();
1757 ETag_surfxml_link();
1763 XBT_DEBUG("Malformed radical");
1767 xbt_dynar_free(&radical_ends);
1769 xbt_dynar_free(&radical_elements);
1773 XBT_DEBUG("<router id=\"%s\"/>", struct_cluster->S_cluster_router_id);
1774 SURFXML_BUFFER_SET(router_id, struct_cluster->S_cluster_router_id);
1775 SURFXML_BUFFER_SET(router_coordinates, "");
1776 SURFXML_START_TAG(router);
1777 SURFXML_END_TAG(router);
1780 if( (struct_cluster->S_cluster_bb_bw!= 0) && (struct_cluster->S_cluster_bb_lat!=0) ){
1781 char *link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1782 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,struct_cluster->S_cluster_bb_bw, struct_cluster->S_cluster_bb_lat);
1784 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1785 if(AX_surfxml_cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1786 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1788 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1789 struct_lnk->V_link_id = xbt_strdup(link_backbone);
1790 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bb_bw;
1791 struct_lnk->V_link_latency = struct_cluster->S_cluster_bb_lat;
1792 struct_lnk->V_link_bandwidth_file = NULL;
1793 struct_lnk->V_link_latency_file = NULL;
1794 struct_lnk->V_link_state_file = NULL;
1795 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1796 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1798 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1799 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1801 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1804 ETag_surfxml_link();
1806 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1807 info->link_up = xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL);
1808 info->link_down = info->link_up;
1809 xbt_dict_set(cluster_host_link,struct_cluster->V_cluster_id,info,xbt_free);
1810 free(link_backbone);
1815 char *new_suffix = xbt_strdup("");
1817 radical_elements = xbt_str_split(struct_cluster->V_cluster_suffix, ".");
1818 xbt_dynar_foreach(radical_elements, iter, groups) {
1819 if (strcmp(groups, "")) {
1820 char *old_suffix = new_suffix;
1821 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1826 xbt_dynar_free(&radical_elements);
1827 xbt_free(new_suffix);
1829 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1830 || strcmp(struct_cluster->V_cluster_state_file,"") )
1831 xbt_dict_free(&patterns);
1834 SURFXML_END_TAG(AS);
1837 surfxml_bufferstack_pop(1);
1840 * This function take a string and replace parameters from patterns dict.
1841 * It returns the new value.
1843 static char* replace_random_parameter(char * string)
1845 char *test_string = NULL;
1847 if(xbt_dict_size(random_value)==0)
1850 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1851 test_string = bprintf("${%s}", string);
1852 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1854 if (strcmp(test_string,"")) { //if not empty, keep this value.
1856 string = test_string;
1857 } //In other case take old value (without ${})
1863 static void clean_routing_after_parse(void)
1865 xbt_dict_free(&random_value);
1866 xbt_dict_free(&patterns);
1869 static void routing_parse_Speer(void)
1871 static int AX_ptr = 0;
1872 char *host_id = NULL;
1873 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1875 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1876 static unsigned int surfxml_buffer_stack_stack[1024];
1878 surfxml_buffer_stack_stack[0] = 0;
1880 surfxml_bufferstack_push(1);
1882 SURFXML_BUFFER_SET(AS_id, struct_peer->V_peer_id);
1884 SURFXML_BUFFER_SET(AS_routing, "Full");
1885 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->V_peer_id);
1887 SURFXML_START_TAG(AS);
1890 host_id = bprintf("peer_%s", struct_peer->V_peer_id);
1891 router_id = bprintf("router_%s", struct_peer->V_peer_id);
1892 link_id_up = bprintf("link_%s_up", struct_peer->V_peer_id);
1893 link_id_down = bprintf("link_%s_down", struct_peer->V_peer_id);
1895 link_router = bprintf("%s_link_router", struct_peer->V_peer_id);
1896 link_backbone = bprintf("%s_backbone", struct_peer->V_peer_id);
1898 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, struct_peer->V_peer_power);
1899 A_surfxml_host_state = A_surfxml_host_state_ON;
1900 SURFXML_BUFFER_SET(host_id, host_id);
1901 SURFXML_BUFFER_SET(host_power, struct_peer->V_peer_power);
1902 SURFXML_BUFFER_SET(host_availability, "1.0");
1903 SURFXML_BUFFER_SET(host_availability_file, struct_peer->V_peer_availability_trace);
1904 SURFXML_BUFFER_SET(host_state_file, struct_peer->V_peer_state_trace);
1905 SURFXML_BUFFER_SET(host_coordinates, "");
1906 SURFXML_BUFFER_SET(host_core, "1.0");
1907 SURFXML_START_TAG(host);
1908 SURFXML_END_TAG(host);
1910 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->V_peer_coord);
1911 SURFXML_BUFFER_SET(router_id, router_id);
1912 SURFXML_BUFFER_SET(router_coordinates, struct_peer->V_peer_coord);
1913 SURFXML_START_TAG(router);
1914 SURFXML_END_TAG(router);
1916 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, struct_peer->V_peer_bw_in, struct_peer->V_peer_lat);
1917 A_surfxml_link_state = A_surfxml_link_state_ON;
1918 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1919 SURFXML_BUFFER_SET(link_id, link_id_up);
1920 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_in);
1921 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1922 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1923 SURFXML_BUFFER_SET(link_latency_file, "");
1924 SURFXML_BUFFER_SET(link_state_file, "");
1925 SURFXML_START_TAG(link);
1926 SURFXML_END_TAG(link);
1928 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, struct_peer->V_peer_bw_out, struct_peer->V_peer_lat);
1929 A_surfxml_link_state = A_surfxml_link_state_ON;
1930 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1931 SURFXML_BUFFER_SET(link_id, link_id_down);
1932 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_out);
1933 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1934 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1935 SURFXML_BUFFER_SET(link_latency_file, "");
1936 SURFXML_BUFFER_SET(link_state_file, "");
1937 SURFXML_START_TAG(link);
1938 SURFXML_END_TAG(link);
1943 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1944 XBT_DEBUG("symmetrical=\"NO\">");
1945 SURFXML_BUFFER_SET(route_src, host_id);
1946 SURFXML_BUFFER_SET(route_dst, router_id);
1947 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1948 SURFXML_START_TAG(route);
1950 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1951 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1952 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1953 SURFXML_START_TAG(link_ctn);
1954 SURFXML_END_TAG(link_ctn);
1956 XBT_DEBUG("</route>");
1957 SURFXML_END_TAG(route);
1960 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1961 XBT_DEBUG("symmetrical=\"NO\">");
1962 SURFXML_BUFFER_SET(route_src, router_id);
1963 SURFXML_BUFFER_SET(route_dst, host_id);
1964 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1965 SURFXML_START_TAG(route);
1967 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
1968 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
1969 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1970 SURFXML_START_TAG(link_ctn);
1971 SURFXML_END_TAG(link_ctn);
1973 XBT_DEBUG("</route>");
1974 SURFXML_END_TAG(route);
1977 SURFXML_END_TAG(AS);
1980 //xbt_dynar_free(&tab_elements_num);
1984 free(link_backbone);
1987 surfxml_bufferstack_pop(1);
1990 static void routing_parse_Srandom(void)
1992 double mean, std, min, max, seed;
1993 char *random_id = A_surfxml_random_id;
1994 char *random_radical = A_surfxml_random_radical;
1995 char *rd_name = NULL;
1997 mean = surf_parse_get_double(A_surfxml_random_mean);
1998 std = surf_parse_get_double(A_surfxml_random_std_deviation);
1999 min = surf_parse_get_double(A_surfxml_random_min);
2000 max = surf_parse_get_double(A_surfxml_random_max);
2001 seed = surf_parse_get_double(A_surfxml_random_seed);
2005 random_data_t random = xbt_new0(s_random_data_t, 1);
2008 xbt_dynar_t radical_elements;
2012 xbt_dynar_t radical_ends;
2014 random->generator = A_surfxml_random_generator;
2015 random->seed = seed;
2019 /* Check user stupidities */
2021 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2023 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2026 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2029 /* normalize the mean and standard deviation before storing */
2030 random->mean = (mean - min) / (max - min);
2031 random->std = std / (max - min);
2033 if (random->mean * (1 - random->mean) < random->std * random->std)
2034 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2035 random->mean, random->std);
2037 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2047 if(xbt_dict_size(random_value)==0)
2048 random_value = xbt_dict_new();
2050 if(!strcmp(random_radical,""))
2052 res = random_generate(random);
2053 rd_value = bprintf("%f",res);
2054 xbt_dict_set(random_value, random_id, rd_value, free);
2058 radical_elements = xbt_str_split(random_radical, ",");
2059 xbt_dynar_foreach(radical_elements, iter, groups) {
2060 radical_ends = xbt_str_split(groups, "-");
2061 switch (xbt_dynar_length(radical_ends)) {
2063 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2064 res = random_generate(random);
2065 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2066 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2071 start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
2072 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
2073 for (i = start; i <= end; i++) {
2074 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2075 res = random_generate(random);
2076 tmpbuf = bprintf("%s%d",random_id,i);
2077 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2082 XBT_INFO("Malformed radical");
2085 res = random_generate(random);
2086 rd_name = bprintf("%s_router",random_id);
2087 rd_value = bprintf("%f",res);
2088 xbt_dict_set(random_value, rd_name, rd_value, free);
2090 xbt_dynar_free(&radical_ends);
2093 xbt_dynar_free(&radical_elements);
2097 static void routing_parse_Erandom(void)
2099 /*xbt_dict_cursor_t cursor = NULL;
2103 xbt_dict_foreach(random_value, cursor, key, elem) {
2104 XBT_DEBUG("%s = %s",key,elem);
2110 * New methods to init the routing model component from the lua script
2115 * add a host to the network element list
2118 void routing_add_host(const char *host_id)
2120 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2124 * Set a new link on the actual list of link for a route or ASroute
2126 void routing_add_link(const char *link_id)
2128 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2132 *Set the endpoints for a route
2134 void routing_set_route(const char *src_id, const char *dst_id)
2136 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2140 * Store the route by calling parse_E_route_store_route
2142 void routing_store_route(void)
2144 parse_E_route_store_route();