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(surf_parsing_host_arg_t h)
191 parse_S_host(h->V_host_id, h->V_host_coord);
193 static void parse_E_host_XML(void)
199 * \brief Add a host to the network element list from lua script
201 static void parse_S_host_lua(const char *host_id, const char *coord)
203 parse_S_host(host_id, coord);
208 * \brief Add a "router" to the network element list
210 static void parse_S_router(void)
212 network_element_info_t info = NULL;
213 if (current_routing->hierarchy == SURF_ROUTING_NULL)
214 current_routing->hierarchy = SURF_ROUTING_BASE;
215 xbt_assert(!xbt_lib_get_or_null(as_router_lib,struct_router->V_router_id, ROUTING_ASR_LEVEL),
216 "Reading a router, processing unit \"%s\" already exists",
217 struct_router->V_router_id);
218 xbt_assert(current_routing->set_processing_unit,
219 "no defined method \"set_processing_unit\" in \"%s\"",
220 current_routing->name);
221 (*(current_routing->set_processing_unit)) (current_routing,
222 struct_router->V_router_id);
223 info = xbt_new0(s_network_element_info_t, 1);
224 info->rc_component = current_routing;
225 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
227 xbt_lib_set(as_router_lib,struct_router->V_router_id,ROUTING_ASR_LEVEL,(void *) info);
228 if (strcmp(A_surfxml_router_coordinates,"")) {
229 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
230 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
231 xbt_dynar_shrink(ctn, 0);
232 xbt_lib_set(as_router_lib,struct_router->V_router_id,COORD_ASR_LEVEL,(void *) ctn);
237 * brief Add a "router" to the network element list from XML description
239 static void parse_S_router_XML(void)
241 return parse_S_router();
245 * brief Add a "router" to the network element list from XML description
247 static void parse_S_router_lua(const char* router_id)
249 struct_router->V_router_id = xbt_strdup(router_id);
250 struct_router->V_router_coord = xbt_strdup("");
251 return parse_S_router();
255 * \brief Set the endponints for a route
257 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
259 if (src != NULL && dst != NULL && link_list != NULL)
260 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
264 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
265 "Some limits are null in the route between \"%s\" and \"%s\"",
267 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
271 * \brief Set the endpoints for a route from XML
273 static void parse_S_route_new_and_endpoints_XML(void)
275 parse_S_route_new_and_endpoints(A_surfxml_route_src,
276 A_surfxml_route_dst);
280 * \brief Set the endpoints for a route from lua
282 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
284 parse_S_route_new_and_endpoints(id_src, id_dst);
288 * \brief Set the endponints and gateways for a ASroute
290 static void parse_S_ASroute_new_and_endpoints(void)
292 if (src != NULL && dst != NULL && link_list != NULL)
293 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
294 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
295 src = A_surfxml_ASroute_src;
296 dst = A_surfxml_ASroute_dst;
297 gw_src = A_surfxml_ASroute_gw_src;
298 gw_dst = A_surfxml_ASroute_gw_dst;
299 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
300 || strlen(gw_dst) > 0,
301 "Some limits are null in the route between \"%s\" and \"%s\"",
303 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
307 * \brief Set the endponints for a bypassRoute
309 static void parse_S_bypassRoute_new_and_endpoints(void)
311 if (src != NULL && dst != NULL && link_list != NULL)
313 "Bypass Route between %s to %s can not be defined",
314 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
315 src = A_surfxml_bypassRoute_src;
316 dst = A_surfxml_bypassRoute_dst;
317 gw_src = A_surfxml_bypassRoute_gw_src;
318 gw_dst = A_surfxml_bypassRoute_gw_dst;
319 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
320 || strlen(gw_dst) > 0,
321 "Some limits are null in the route between \"%s\" and \"%s\"",
323 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
327 * \brief Set a new link on the actual list of link for a route or ASroute
329 static void parse_E_link_ctn_new_elem(const char *link_id)
332 val = xbt_strdup(link_id);
333 xbt_dynar_push(link_list, &val);
337 * \brief Set a new link on the actual list of link for a route or ASroute from XML
340 static void parse_E_link_ctn_new_elem_XML(void)
342 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
343 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
344 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
345 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
346 parse_E_link_ctn_new_elem(link_id);
349 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
350 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
351 parse_E_link_ctn_new_elem(link_id);
357 * \brief Set a new link on the actual list of link for a route or ASroute from lua
359 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
361 parse_E_link_ctn_new_elem(link_id);
365 * \brief Store the route by calling the set_route function of the current routing component
367 static void parse_E_route_store_route(void)
369 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
370 route->generic_route.link_list = link_list;
371 xbt_assert(current_routing->set_route,
372 "no defined method \"set_route\" in \"%s\"",
373 current_routing->name);
374 (*(current_routing->set_route)) (current_routing, src, dst, route);
381 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
383 static void parse_E_ASroute_store_route(void)
385 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
386 e_route->generic_route.link_list = link_list;
387 e_route->src_gateway = xbt_strdup(gw_src);
388 e_route->dst_gateway = xbt_strdup(gw_dst);
389 xbt_assert(current_routing->set_ASroute,
390 "no defined method \"set_ASroute\" in \"%s\"",
391 current_routing->name);
392 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
401 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
403 static void parse_E_bypassRoute_store_route(void)
405 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
406 e_route->generic_route.link_list = link_list;
407 e_route->src_gateway = xbt_strdup(gw_src);
408 e_route->dst_gateway = xbt_strdup(gw_dst);
409 xbt_assert(current_routing->set_bypassroute,
410 "no defined method \"set_bypassroute\" in \"%s\"",
411 current_routing->name);
412 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
422 * \brief Make a new routing component to the platform
424 * Add a new autonomous system to the platform. Any elements (such as host,
425 * router or sub-AS) added after this call and before the corresponding call
426 * to sg_platf_new_AS_close() will be added to this AS.
428 * Once this function was called, the configuration concerning the used
429 * models cannot be changed anymore.
431 * @param AS_id name of this autonomous system. Must be uniq in the platform
432 * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
434 void sg_platf_new_AS_open(const char *AS_id, const char *wanted_routing_type)
436 routing_component_t new_routing;
437 model_type_t model = NULL;
440 surf_parse_models_setup(); /* ensure that the models are created after the last <config> tag and before the first <AS>-like */
442 /* search the routing model */
443 for (cpt = 0; routing_models[cpt].name; cpt++)
444 if (!strcmp(wanted_routing_type, routing_models[cpt].name))
445 model = &routing_models[cpt];
446 /* if its not exist, error */
448 fprintf(stderr, "Routing model %s not found. Existing models:\n",
449 wanted_routing_type);
450 for (cpt = 0; routing_models[cpt].name; cpt++)
451 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
452 routing_models[cpt].desc);
456 /* make a new routing component */
457 new_routing = (routing_component_t) (*(model->create)) ();
458 new_routing->routing = model;
459 new_routing->hierarchy = SURF_ROUTING_NULL;
460 new_routing->name = xbt_strdup(AS_id);
461 new_routing->routing_sons = xbt_dict_new();
463 /* Hack for Vivaldi */
464 if(!strcmp(model->name,"Vivaldi"))
465 new_routing->get_latency = vivaldi_get_link_latency;
467 if (current_routing == NULL && global_routing->root == NULL) {
469 /* it is the first one */
470 new_routing->routing_father = NULL;
471 global_routing->root = new_routing;
473 } else if (current_routing != NULL && global_routing->root != NULL) {
475 xbt_assert(!xbt_dict_get_or_null
476 (current_routing->routing_sons, AS_id),
477 "The AS \"%s\" already exists", AS_id);
478 /* it is a part of the tree */
479 new_routing->routing_father = current_routing;
480 /* set the father behavior */
481 if (current_routing->hierarchy == SURF_ROUTING_NULL)
482 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
483 /* add to the sons dictionary */
484 xbt_dict_set(current_routing->routing_sons, AS_id,
485 (void *) new_routing, NULL);
486 /* add to the father element list */
487 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
488 /* unload the prev parse rules */
489 (*(current_routing->routing->unload)) ();
492 THROWF(arg_error, 0, "All defined components must be belong to a AS");
494 /* set the new parse rules */
495 (*(new_routing->routing->load)) ();
496 /* set the new current component of the tree */
497 current_routing = new_routing;
501 * \brief Specify that the current description of AS is finished
503 * Once you've declared all the content of your AS, you have to close
504 * it with this call. Your AS is not usable until you call this function.
506 * @fixme: this call is not as robust as wanted: bad things WILL happen
507 * if you call it twice for the same AS, or if you forget calling it, or
508 * even if you add stuff to a closed AS
511 void sg_platf_new_AS_close() {
513 if (current_routing == NULL) {
514 THROWF(arg_error, 0, "Close an AS, but none was under construction");
516 network_element_info_t info = NULL;
517 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
518 "The AS \"%s\" already exists",current_routing->name);
519 info = xbt_new0(s_network_element_info_t, 1);
520 info->rc_component = current_routing->routing_father;
521 info->rc_type = SURF_NETWORK_ELEMENT_AS;
522 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
524 (*(current_routing->routing->unload)) ();
525 (*(current_routing->routing->end)) ();
526 current_routing = current_routing->routing_father;
527 if (current_routing != NULL)
528 (*(current_routing->routing->load)) ();
532 /* Aux Business methods */
535 * \brief Get the AS name of the element
537 * \param name the host name
540 static char* elements_As_name(const char *name)
542 routing_component_t as_comp;
544 /* (1) find the as where the host is located */
545 as_comp = ((network_element_info_t)
546 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
547 return as_comp->name;
552 * \brief Get the AS father and the first elements of the chain
554 * \param src the source host name
555 * \param dst the destination host name
557 * Get the common father of the to processing units, and the first different
558 * father in the chain
560 static void elements_father(const char *src, const char *dst,
561 routing_component_t *res_father,
562 routing_component_t *res_src,
563 routing_component_t *res_dst)
565 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
566 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
567 routing_component_t src_as, dst_as;
568 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
569 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
572 routing_component_t current;
573 routing_component_t current_src;
574 routing_component_t current_dst;
575 routing_component_t father;
577 /* (1) find the as where the src and dst are located */
578 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
580 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
583 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
585 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
586 src_as = src_data->rc_component;
587 dst_as = dst_data->rc_component;
589 xbt_assert(src_as && dst_as,
590 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
592 /* (2) find the path to the root routing component */
593 for (current = src_as ; current != NULL ; current = current->routing_father) {
594 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
595 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
596 path_src[index_src++] = current;
598 for (current = dst_as ; current != NULL ; current = current->routing_father) {
599 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
600 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
601 path_dst[index_dst++] = current;
604 /* (3) find the common father */
606 current_src = path_src[--index_src];
607 current_dst = path_dst[--index_dst];
608 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
610 /* (4) they are not in the same routing component, make the path */
611 if (current_src == current_dst)
612 father = current_src;
614 father = path_src[index_src + 1];
616 /* (5) result generation */
617 *res_father = father; /* first the common father of src and dst */
618 *res_src = current_src; /* second the first different father of src */
619 *res_dst = current_dst; /* three the first different father of dst */
621 #undef ELEMENTS_FATHER_MAXDEPTH
624 /* Global Business methods */
627 * \brief Recursive function for get_route_latency
629 * \param src the source host name
630 * \param dst the destination host name
631 * \param *e_route the route where the links are stored
632 * \param *latency the latency, if needed
634 * This function is called by "get_route" and "get_latency". It allows to walk
635 * recursively through the routing components tree.
637 static void _get_route_latency(const char *src, const char *dst,
638 xbt_dynar_t *route, double *latency)
640 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
641 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
643 routing_component_t common_father;
644 routing_component_t src_father;
645 routing_component_t dst_father;
646 elements_father(src, dst, &common_father, &src_father, &dst_father);
648 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
650 route_extended_t e_route = NULL;
652 e_route = common_father->get_route(common_father, src, dst);
653 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
654 *route = e_route->generic_route.link_list;
657 *latency = common_father->get_latency(common_father, src, dst, e_route);
658 xbt_assert(*latency >= 0.0,
659 "latency error on route between \"%s\" and \"%s\"", src, dst);
662 xbt_free(e_route->src_gateway);
663 xbt_free(e_route->dst_gateway);
667 } else { /* SURF_ROUTING_RECURSIVE */
669 route_extended_t e_route_bypass = NULL;
670 if (common_father->get_bypass_route)
671 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
673 xbt_assert(!latency || !e_route_bypass,
674 "Bypass cannot work yet with get_latency");
676 route_extended_t e_route_cnt = e_route_bypass
678 : common_father->get_route(common_father,
679 src_father->name, dst_father->name);
681 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
682 src_father->name, dst_father->name);
684 xbt_assert((e_route_cnt->src_gateway == NULL) ==
685 (e_route_cnt->dst_gateway == NULL),
686 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
689 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
692 *latency = common_father->get_latency(common_father,
693 src_father->name, dst_father->name,
695 xbt_assert(*latency >= 0.0,
696 "latency error on route between \"%s\" and \"%s\"",
697 src_father->name, dst_father->name);
703 if (strcmp(src, e_route_cnt->src_gateway)) {
705 xbt_dynar_t route_src;
707 _get_route_latency(src, e_route_cnt->src_gateway,
708 (route ? &route_src : NULL),
709 (latency ? &latency_src : NULL));
711 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
712 src, e_route_cnt->src_gateway);
713 xbt_dynar_foreach(route_src, cpt, link) {
714 xbt_dynar_push(*route, &link);
716 xbt_dynar_free(&route_src);
719 xbt_assert(latency_src >= 0.0,
720 "latency error on route between \"%s\" and \"%s\"",
721 src, e_route_cnt->src_gateway);
722 *latency += latency_src;
727 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
728 xbt_dynar_push(*route, &link);
732 if (strcmp(e_route_cnt->dst_gateway, dst)) {
734 xbt_dynar_t route_dst;
736 _get_route_latency(e_route_cnt->dst_gateway, dst,
737 (route ? &route_dst : NULL),
738 (latency ? &latency_dst : NULL));
740 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
741 e_route_cnt->dst_gateway, dst);
742 xbt_dynar_foreach(route_dst, cpt, link) {
743 xbt_dynar_push(*route, &link);
745 xbt_dynar_free(&route_dst);
748 xbt_assert(latency_dst >= 0.0,
749 "latency error on route between \"%s\" and \"%s\"",
750 e_route_cnt->dst_gateway, dst);
751 *latency += latency_dst;
755 generic_free_extended_route(e_route_cnt);
760 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
762 static void get_route_latency(const char *src, const char *dst,
763 xbt_dynar_t *route, double *latency, int cleanup)
765 _get_route_latency(src, dst, route, latency);
766 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
767 xbt_assert(!latency || *latency >= 0.0,
768 "latency error on route between \"%s\" and \"%s\"", src, dst);
770 xbt_dynar_free(&global_routing->last_route);
771 global_routing->last_route = cleanup ? *route : NULL;
776 * \brief Generic method: find a route between hosts
778 * \param src the source host name
779 * \param dst the destination host name
781 * walk through the routing components tree and find a route between hosts
782 * by calling the differents "get_route" functions in each routing component.
783 * No need to free the returned dynar. It will be freed at the next call.
785 static xbt_dynar_t get_route(const char *src, const char *dst)
787 xbt_dynar_t route = NULL;
788 get_route_latency(src, dst, &route, NULL, 1);
793 * \brief Generic method: find a route between hosts
795 * \param src the source host name
796 * \param dst the destination host name
798 * same as get_route, but return NULL if any exception is raised.
800 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
802 xbt_dynar_t route = NULL;
805 get_route_latency(src, dst, &route, NULL, 1);
807 xbt_ex_free(exception);
814 * \brief Generic method: find a route between hosts
816 * \param src the source host name
817 * \param dst the destination host name
819 * walk through the routing components tree and find a route between hosts
820 * by calling the differents "get_route" functions in each routing component.
821 * Leaves the caller the responsability to clean the returned dynar.
823 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
825 xbt_dynar_t route = NULL;
826 get_route_latency(src, dst, &route, NULL, 0);
831 static double get_latency(const char *src, const char *dst)
833 double latency = -1.0;
834 get_route_latency(src, dst, NULL, &latency, 0);
838 static int surf_parse_models_setup_already_called=0;
839 /* Call the last initialization functions, that must be called after the
840 * <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
842 void surf_parse_models_setup()
844 if (surf_parse_models_setup_already_called)
846 surf_parse_models_setup_already_called=1;
847 routing_parse_Erandom();
848 surf_config_models_setup();
853 * \brief Recursive function for finalize
855 * \param rc the source host name
857 * This fuction is call by "finalize". It allow to finalize the
858 * AS or routing components. It delete all the structures.
860 static void _finalize(routing_component_t rc)
863 xbt_dict_cursor_t cursor = NULL;
865 routing_component_t elem;
866 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
869 xbt_dict_t tmp_sons = rc->routing_sons;
870 char *tmp_name = rc->name;
871 xbt_dict_free(&tmp_sons);
873 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
874 current_routing->name);
875 (*(rc->finalize)) (rc);
880 * \brief Generic method: delete all the routing structures
882 * walk through the routing components tree and delete the structures
883 * by calling the differents "finalize" functions in each routing component
885 static void finalize(void)
887 /* delete recursibly all the tree */
888 _finalize(global_routing->root);
889 /* delete last_route */
890 xbt_dynar_free(&(global_routing->last_route));
891 /* delete global routing structure */
892 xbt_free(global_routing);
893 /* make sure that we will reinit the models while loading the platf once reinited -- HACK but there is no proper surf_routing_init() */
894 surf_parse_models_setup_already_called = 0;
897 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
899 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
901 //adding my one link routes
904 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
906 xbt_dynar_foreach(onelink_mine, cpt, link) {
907 xbt_dynar_push(ret, &link);
912 xbt_dict_cursor_t cursor = NULL;
913 routing_component_t rc_child;
914 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
915 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
917 xbt_dynar_foreach(onelink_child, cpt, link) {
918 xbt_dynar_push(ret, &link);
925 static xbt_dynar_t get_onelink_routes(void)
927 return recursive_get_onelink_routes(global_routing->root);
930 e_surf_network_element_type_t get_network_element_type(const char
933 network_element_info_t rc = NULL;
935 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
936 if(rc) return rc->rc_type;
938 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
939 if(rc) return rc->rc_type;
941 return SURF_NETWORK_ELEMENT_NULL;
945 * \brief Generic method: create the global routing schema
947 * Make a global routing structure and set all the parsing functions.
949 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
951 /* config the uniq global routing */
952 global_routing = xbt_new0(s_routing_global_t, 1);
953 global_routing->root = NULL;
954 global_routing->get_route = get_route;
955 global_routing->get_route_or_null = get_route_or_null;
956 global_routing->get_latency = get_latency;
957 global_routing->get_route_no_cleanup = get_route_no_cleanup;
958 global_routing->get_onelink_routes = get_onelink_routes;
959 global_routing->get_route_latency = get_route_latency;
960 global_routing->get_network_element_type = get_network_element_type;
961 global_routing->finalize = finalize;
962 global_routing->loopback = loopback;
963 global_routing->size_of_link = size_of_links;
964 global_routing->last_route = NULL;
965 get_link_latency = get_link_latency_fun;
966 /* no current routing at moment */
967 current_routing = NULL;
969 /* parse generic elements */
970 surf_parse_host_add_cb(parse_S_host_XML);
971 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
972 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
974 surfxml_add_callback(STag_surfxml_route_cb_list,
975 &parse_S_route_new_and_endpoints_XML);
976 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
977 &parse_S_ASroute_new_and_endpoints);
978 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
979 &parse_S_bypassRoute_new_and_endpoints);
981 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
982 &parse_E_link_ctn_new_elem_XML);
984 surfxml_add_callback(ETag_surfxml_route_cb_list,
985 &parse_E_route_store_route);
986 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
987 &parse_E_ASroute_store_route);
988 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
989 &parse_E_bypassRoute_store_route);
991 surfxml_add_callback(STag_surfxml_cluster_cb_list,
992 &routing_parse_Scluster);
994 surfxml_add_callback(STag_surfxml_peer_cb_list,
995 &routing_parse_Speer);
997 surfxml_add_callback(ETag_surfxml_platform_cb_list,
998 &clean_routing_after_parse);
1001 instr_routing_define_callbacks();
1005 void surf_parse_add_callback_config(void)
1007 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1008 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1011 /* ************************************************** */
1012 /* ********** PATERN FOR NEW ROUTING **************** */
1014 /* The minimal configuration of a new routing model need the next functions,
1015 * also you need to set at the start of the file, the new model in the model
1016 * list. Remember keep the null ending of the list.
1018 /*** Routing model structure ***/
1020 // s_routing_component_t generic_routing;
1021 // /* things that your routing model need */
1022 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1024 /*** Parse routing model functions ***/
1025 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1026 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1027 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1028 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1029 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1031 /*** Business methods ***/
1032 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1033 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1034 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1036 /*** Creation routing model functions ***/
1037 // static void* model_NEW_create(void) {
1038 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1039 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1040 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1041 // new_component->generic_routing.set_route = model_NEW_set_route;
1042 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1043 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1044 // new_component->generic_routing.get_route = NEW_get_route;
1045 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1046 // new_component->generic_routing.finalize = NEW_finalize;
1047 // /* initialization of internal structures */
1048 // return new_component;
1049 // } /* mandatory */
1050 // static void model_NEW_load(void) {} /* mandatory */
1051 // static void model_NEW_unload(void) {} /* mandatory */
1052 // static void model_NEW_end(void) {} /* mandatory */
1054 /* ************************************************************************** */
1055 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1057 void generic_set_processing_unit(routing_component_t rc,
1060 XBT_DEBUG("Load process unit \"%s\"", name);
1061 int *id = xbt_new0(int, 1);
1062 xbt_dict_t _to_index;
1063 _to_index = current_routing->to_index;
1064 *id = xbt_dict_length(_to_index);
1065 xbt_dict_set(_to_index, name, id, xbt_free);
1068 void generic_set_autonomous_system(routing_component_t rc,
1071 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1072 int *id = xbt_new0(int, 1);
1073 xbt_dict_t _to_index;
1074 _to_index = current_routing->to_index;
1075 *id = xbt_dict_length(_to_index);
1076 xbt_dict_set(_to_index, name, id, xbt_free);
1079 int surf_pointer_resource_cmp(const void *a, const void *b)
1084 int surf_link_resource_cmp(const void *a, const void *b)
1086 return !!memcmp(a,b,global_routing->size_of_link);
1089 void generic_set_bypassroute(routing_component_t rc,
1090 const char *src, const char *dst,
1091 route_extended_t e_route)
1093 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1094 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1097 route_name = bprintf("%s#%s", src, dst);
1098 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1099 "Invalid count of links, must be greater than zero (%s,%s)",
1101 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1102 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1103 src, e_route->src_gateway, dst, e_route->dst_gateway);
1105 route_extended_t new_e_route =
1106 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1107 xbt_dynar_free(&(e_route->generic_route.link_list));
1110 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1111 (void (*)(void *)) generic_free_extended_route);
1112 xbt_free(route_name);
1115 /* ************************************************************************** */
1116 /* *********************** GENERIC BUSINESS METHODS ************************* */
1118 double generic_get_link_latency(routing_component_t rc,
1119 const char *src, const char *dst,
1120 route_extended_t route)
1122 int need_to_clean = route?0:1;
1125 double latency = 0.0;
1127 route = route?route:rc->get_route(rc,src,dst);
1129 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1130 latency += get_link_latency(link);
1132 if(need_to_clean) generic_free_extended_route(route);
1136 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1138 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1141 route_extended_t generic_get_bypassroute(routing_component_t rc,
1145 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1146 routing_component_t src_as, dst_as;
1147 int index_src, index_dst;
1148 xbt_dynar_t path_src = NULL;
1149 xbt_dynar_t path_dst = NULL;
1150 routing_component_t current = NULL;
1151 routing_component_t *current_src = NULL;
1152 routing_component_t *current_dst = NULL;
1154 /* (1) find the as where the src and dst are located */
1155 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1156 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1157 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1158 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1160 if(src_data == NULL || dst_data == NULL)
1161 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1162 src, dst, rc->name);
1164 src_as = ((network_element_info_t)src_data)->rc_component;
1165 dst_as = ((network_element_info_t)dst_data)->rc_component;
1167 /* (2) find the path to the root routing component */
1168 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1170 while (current != NULL) {
1171 xbt_dynar_push(path_src, ¤t);
1172 current = current->routing_father;
1174 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1176 while (current != NULL) {
1177 xbt_dynar_push(path_dst, ¤t);
1178 current = current->routing_father;
1181 /* (3) find the common father */
1182 index_src = path_src->used - 1;
1183 index_dst = path_dst->used - 1;
1184 current_src = xbt_dynar_get_ptr(path_src, index_src);
1185 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1186 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1187 xbt_dynar_pop_ptr(path_src);
1188 xbt_dynar_pop_ptr(path_dst);
1191 current_src = xbt_dynar_get_ptr(path_src, index_src);
1192 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1195 int max_index_src = path_src->used - 1;
1196 int max_index_dst = path_dst->used - 1;
1198 int max_index = max(max_index_src, max_index_dst);
1201 route_extended_t e_route_bypass = NULL;
1203 for (max = 0; max <= max_index; max++) {
1204 for (i = 0; i < max; i++) {
1205 if (i <= max_index_src && max <= max_index_dst) {
1206 char *route_name = bprintf("%s#%s",
1207 (*(routing_component_t *)
1209 (path_src, i)))->name,
1210 (*(routing_component_t *)
1212 (path_dst, max)))->name);
1214 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1215 xbt_free(route_name);
1219 if (max <= max_index_src && i <= max_index_dst) {
1220 char *route_name = bprintf("%s#%s",
1221 (*(routing_component_t *)
1223 (path_src, max)))->name,
1224 (*(routing_component_t *)
1226 (path_dst, i)))->name);
1228 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1229 xbt_free(route_name);
1238 if (max <= max_index_src && max <= max_index_dst) {
1239 char *route_name = bprintf("%s#%s",
1240 (*(routing_component_t *)
1242 (path_src, max)))->name,
1243 (*(routing_component_t *)
1245 (path_dst, max)))->name);
1246 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1247 xbt_free(route_name);
1253 xbt_dynar_free(&path_src);
1254 xbt_dynar_free(&path_dst);
1256 route_extended_t new_e_route = NULL;
1258 if (e_route_bypass) {
1260 unsigned int cpt = 0;
1261 new_e_route = xbt_new0(s_route_extended_t, 1);
1262 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1263 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1264 new_e_route->generic_route.link_list =
1265 xbt_dynar_new(global_routing->size_of_link, NULL);
1266 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1267 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1274 /* ************************************************************************** */
1275 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1278 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1279 void *data, int order)
1285 xbt_dynar_t links = NULL, links_id = NULL;
1287 new_route = xbt_new0(s_route_t, 1);
1288 new_route->link_list =
1289 xbt_dynar_new(global_routing->size_of_link, NULL);
1291 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1292 "the hierarchy type is not SURF_ROUTING_BASE");
1294 links = ((route_t) data)->link_list;
1297 links_id = new_route->link_list;
1299 xbt_dynar_foreach(links, cpt, link_name) {
1302 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1305 xbt_dynar_push(links_id, &link);
1307 xbt_dynar_unshift(links_id, &link);
1309 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1316 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1317 void *data, int order)
1321 route_extended_t e_route, new_e_route;
1324 xbt_dynar_t links = NULL, links_id = NULL;
1326 new_e_route = xbt_new0(s_route_extended_t, 1);
1327 new_e_route->generic_route.link_list =
1328 xbt_dynar_new(global_routing->size_of_link, NULL);
1329 new_e_route->src_gateway = NULL;
1330 new_e_route->dst_gateway = NULL;
1332 xbt_assert(hierarchy == SURF_ROUTING_BASE
1333 || hierarchy == SURF_ROUTING_RECURSIVE,
1334 "the hierarchy type is not defined");
1336 if (hierarchy == SURF_ROUTING_BASE) {
1338 route = (route_t) data;
1339 links = route->link_list;
1341 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1343 e_route = (route_extended_t) data;
1344 xbt_assert(e_route->src_gateway
1345 && e_route->dst_gateway, "bad gateway, is null");
1346 links = e_route->generic_route.link_list;
1348 /* remeber not erase the gateway names */
1349 new_e_route->src_gateway = strdup(e_route->src_gateway);
1350 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1353 links_id = new_e_route->generic_route.link_list;
1355 xbt_dynar_foreach(links, cpt, link_name) {
1358 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1361 xbt_dynar_push(links_id, &link);
1363 xbt_dynar_unshift(links_id, &link);
1365 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1371 void generic_free_route(route_t route)
1374 xbt_dynar_free(&(route->link_list));
1379 void generic_free_extended_route(route_extended_t e_route)
1382 xbt_dynar_free(&(e_route->generic_route.link_list));
1383 if (e_route->src_gateway)
1384 xbt_free(e_route->src_gateway);
1385 if (e_route->dst_gateway)
1386 xbt_free(e_route->dst_gateway);
1391 static routing_component_t generic_as_exist(routing_component_t find_from,
1392 routing_component_t to_find)
1394 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1395 xbt_dict_cursor_t cursor = NULL;
1398 routing_component_t elem;
1399 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1400 if (to_find == elem || generic_as_exist(elem, to_find)) {
1411 generic_autonomous_system_exist(routing_component_t rc, char *element)
1413 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1414 routing_component_t element_as, result, elem;
1415 xbt_dict_cursor_t cursor = NULL;
1417 element_as = ((network_element_info_t)
1418 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1419 result = ((routing_component_t) - 1);
1420 if (element_as != rc)
1421 result = generic_as_exist(rc, element_as);
1425 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1426 found = !strcmp(elem->name, element);
1437 generic_processing_units_exist(routing_component_t rc, char *element)
1439 routing_component_t element_as;
1440 element_as = ((network_element_info_t)
1441 xbt_lib_get_or_null(host_lib,
1442 element, ROUTING_HOST_LEVEL))->rc_component;
1443 if (element_as == rc)
1445 return generic_as_exist(rc, element_as);
1448 void generic_src_dst_check(routing_component_t rc, const char *src,
1452 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1453 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1454 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1455 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1457 if(src_data == NULL || dst_data == NULL)
1458 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1459 src, dst, rc->name);
1461 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1462 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1464 if(src_as != dst_as)
1465 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1466 src, src_as->name, dst, dst_as->name);
1468 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1469 src,dst,src_as->name, dst_as->name,rc->name);
1473 static void parse_create_host_link(int i)
1475 char *host_id, *link_id = NULL;
1476 s_surf_parsing_host_arg_t host;
1477 memset(&host,0,sizeof(host));
1479 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1480 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1482 A_surfxml_host_state = A_surfxml_host_state_ON;
1484 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1485 host.V_host_id = xbt_strdup(host_id);
1486 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1487 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1488 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1489 xbt_str_varsubst(tmp_availability_file,patterns);
1490 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1491 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1492 xbt_free(tmp_availability_file);
1496 XBT_DEBUG("\tavailability_file=\"\"");
1498 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1499 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1500 xbt_str_varsubst(tmp_state_file,patterns);
1501 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1502 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1503 xbt_free(tmp_state_file);
1507 XBT_DEBUG("\tstate_file=\"\"");
1510 host.V_host_power_peak = struct_cluster->S_cluster_power;
1511 host.V_host_power_scale = 1.0;
1512 host.V_host_core = struct_cluster->S_cluster_core;
1513 host.V_host_state_initial = SURF_RESOURCE_ON;
1514 host.V_host_coord = "";
1515 sg_platf_new_host(&host);
1516 XBT_DEBUG("</host>");
1518 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1519 if(AX_surfxml_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1520 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1521 if(AX_surfxml_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1522 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1524 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1526 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1527 struct_lnk->V_link_id = xbt_strdup(link_id);
1528 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1529 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1530 struct_lnk->V_link_bandwidth_file = NULL;
1531 struct_lnk->V_link_latency_file = NULL;
1532 struct_lnk->V_link_state_file = NULL;
1533 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1534 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1536 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1537 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1540 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1541 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1542 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1543 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1547 ETag_surfxml_host();
1548 ETag_surfxml_link();
1550 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1552 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX){
1553 char* tmp_link = bprintf("%s_UP",link_id);
1554 info->link_up = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1556 tmp_link = bprintf("%s_DOWN",link_id);
1557 info->link_down = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1561 info->link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
1562 info->link_down = info->link_up;
1564 xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
1569 void routing_parse_Scluster(void)
1571 if(!cluster_host_link)
1572 cluster_host_link = xbt_dict_new();
1574 static int AX_ptr = 0;
1575 char *host_id, *groups, *link_id = NULL;
1577 s_surf_parsing_host_arg_t host;
1579 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1580 || strcmp(struct_cluster->V_cluster_state_file,"") )
1582 if(xbt_dict_size(patterns)==0)
1583 patterns = xbt_dict_new();
1584 xbt_dict_set(patterns,"id",struct_cluster->V_cluster_id,NULL);
1585 xbt_dict_set(patterns,"prefix",struct_cluster->V_cluster_prefix,NULL);
1586 xbt_dict_set(patterns,"suffix",struct_cluster->V_cluster_suffix,NULL);
1591 xbt_dynar_t radical_elements;
1592 xbt_dynar_t radical_ends;
1594 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1595 static unsigned int surfxml_buffer_stack_stack[1024];
1597 surfxml_buffer_stack_stack[0] = 0;
1598 surfxml_bufferstack_push(1);
1600 SURFXML_BUFFER_SET(AS_id, struct_cluster->V_cluster_id);
1601 SURFXML_BUFFER_SET(AS_routing, "Cluster");
1602 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", struct_cluster->V_cluster_id);
1603 SURFXML_START_TAG(AS);
1606 radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ",");
1607 xbt_dynar_foreach(radical_elements, iter, groups) {
1608 memset(&host,0,sizeof(host));
1610 radical_ends = xbt_str_split(groups, "-");
1611 switch (xbt_dynar_length(radical_ends)) {
1613 start=surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1614 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, start, struct_cluster->V_cluster_suffix);
1615 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start);
1617 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1618 host.V_host_id = host_id;
1619 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1620 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1621 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1622 xbt_str_varsubst(tmp_availability_file,patterns);
1623 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1624 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1625 xbt_free(tmp_availability_file);
1629 XBT_DEBUG("\tavailability_file=\"\"");
1631 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1632 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1633 xbt_str_varsubst(tmp_state_file,patterns);
1634 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1635 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1636 xbt_free(tmp_state_file);
1640 XBT_DEBUG("\tstate_file=\"\"");
1643 host.V_host_power_peak = struct_cluster->S_cluster_power;
1644 host.V_host_power_scale = 1.0;
1645 host.V_host_core = struct_cluster->S_cluster_core;
1646 host.V_host_state_initial = SURF_RESOURCE_ON;
1647 host.V_host_coord = "";
1648 sg_platf_new_host(&host);
1649 XBT_DEBUG("</host>");
1651 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1652 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1653 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1654 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1655 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1657 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1659 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1660 struct_lnk->V_link_id = link_id;
1661 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1662 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1663 struct_lnk->V_link_bandwidth_file = NULL;
1664 struct_lnk->V_link_latency_file = NULL;
1665 struct_lnk->V_link_state_file = NULL;
1666 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1667 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1669 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1670 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1673 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1674 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1675 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1676 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1680 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1681 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1682 ETag_surfxml_host();
1683 ETag_surfxml_link();
1689 start=surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1690 end= surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
1691 for (i = start; i <= end; i++) {
1692 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1693 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1695 A_surfxml_host_state = A_surfxml_host_state_ON;
1697 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1698 host.V_host_id = host_id;
1699 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1700 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1701 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1702 xbt_str_varsubst(tmp_availability_file,patterns);
1703 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1704 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1705 xbt_free(tmp_availability_file);
1709 XBT_DEBUG("\tavailability_file=\"\"");
1711 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1712 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1713 xbt_str_varsubst(tmp_state_file,patterns);
1714 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1715 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1716 xbt_free(tmp_state_file);
1720 XBT_DEBUG("\tstate_file=\"\"");
1723 host.V_host_power_peak = struct_cluster->S_cluster_power;
1724 host.V_host_power_scale = 1.0;
1725 host.V_host_core = struct_cluster->S_cluster_core;
1726 host.V_host_state_initial = SURF_RESOURCE_ON;
1727 host.V_host_coord = "";
1728 sg_platf_new_host(&host);
1729 XBT_DEBUG("</host>");
1731 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1732 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1733 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1734 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1735 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1737 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1739 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1740 struct_lnk->V_link_id = link_id;
1741 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1742 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1743 struct_lnk->V_link_bandwidth_file = NULL;
1744 struct_lnk->V_link_latency_file = NULL;
1745 struct_lnk->V_link_state_file = NULL;
1746 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1747 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1749 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1750 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1753 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1754 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1755 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1756 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1760 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1761 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1763 ETag_surfxml_host();
1764 ETag_surfxml_link();
1770 XBT_DEBUG("Malformed radical");
1774 xbt_dynar_free(&radical_ends);
1776 xbt_dynar_free(&radical_elements);
1780 XBT_DEBUG("<router id=\"%s\"/>", struct_cluster->S_cluster_router_id);
1781 SURFXML_BUFFER_SET(router_id, struct_cluster->S_cluster_router_id);
1782 SURFXML_BUFFER_SET(router_coordinates, "");
1783 SURFXML_START_TAG(router);
1784 SURFXML_END_TAG(router);
1787 if( (struct_cluster->S_cluster_bb_bw!= 0) && (struct_cluster->S_cluster_bb_lat!=0) ){
1788 char *link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1789 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,struct_cluster->S_cluster_bb_bw, struct_cluster->S_cluster_bb_lat);
1791 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1792 if(AX_surfxml_cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1793 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1795 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1796 struct_lnk->V_link_id = xbt_strdup(link_backbone);
1797 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bb_bw;
1798 struct_lnk->V_link_latency = struct_cluster->S_cluster_bb_lat;
1799 struct_lnk->V_link_bandwidth_file = NULL;
1800 struct_lnk->V_link_latency_file = NULL;
1801 struct_lnk->V_link_state_file = NULL;
1802 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1803 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1805 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1806 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1808 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1811 ETag_surfxml_link();
1813 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1814 info->link_up = xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL);
1815 info->link_down = info->link_up;
1816 xbt_dict_set(cluster_host_link,struct_cluster->V_cluster_id,info,xbt_free);
1817 free(link_backbone);
1822 char *new_suffix = xbt_strdup("");
1824 radical_elements = xbt_str_split(struct_cluster->V_cluster_suffix, ".");
1825 xbt_dynar_foreach(radical_elements, iter, groups) {
1826 if (strcmp(groups, "")) {
1827 char *old_suffix = new_suffix;
1828 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1833 xbt_dynar_free(&radical_elements);
1834 xbt_free(new_suffix);
1836 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1837 || strcmp(struct_cluster->V_cluster_state_file,"") )
1838 xbt_dict_free(&patterns);
1841 SURFXML_END_TAG(AS);
1844 surfxml_bufferstack_pop(1);
1847 * This function take a string and replace parameters from patterns dict.
1848 * It returns the new value.
1850 static char* replace_random_parameter(char * string)
1852 char *test_string = NULL;
1854 if(xbt_dict_size(random_value)==0)
1857 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1858 test_string = bprintf("${%s}", string);
1859 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1861 if (strcmp(test_string,"")) { //if not empty, keep this value.
1863 string = test_string;
1864 } //In other case take old value (without ${})
1870 static void clean_routing_after_parse(void)
1872 xbt_dict_free(&random_value);
1873 xbt_dict_free(&patterns);
1876 static void routing_parse_Speer(void)
1878 static int AX_ptr = 0;
1879 char *host_id = NULL;
1880 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1882 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1883 static unsigned int surfxml_buffer_stack_stack[1024];
1885 surfxml_buffer_stack_stack[0] = 0;
1887 surfxml_bufferstack_push(1);
1889 SURFXML_BUFFER_SET(AS_id, struct_peer->V_peer_id);
1891 SURFXML_BUFFER_SET(AS_routing, "Full");
1892 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->V_peer_id);
1894 SURFXML_START_TAG(AS);
1897 host_id = bprintf("peer_%s", struct_peer->V_peer_id);
1898 router_id = bprintf("router_%s", struct_peer->V_peer_id);
1899 link_id_up = bprintf("link_%s_up", struct_peer->V_peer_id);
1900 link_id_down = bprintf("link_%s_down", struct_peer->V_peer_id);
1902 link_router = bprintf("%s_link_router", struct_peer->V_peer_id);
1903 link_backbone = bprintf("%s_backbone", struct_peer->V_peer_id);
1905 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, struct_peer->V_peer_power);
1906 A_surfxml_host_state = A_surfxml_host_state_ON;
1907 SURFXML_BUFFER_SET(host_id, host_id);
1908 SURFXML_BUFFER_SET(host_power, struct_peer->V_peer_power);
1909 SURFXML_BUFFER_SET(host_availability, "1.0");
1910 SURFXML_BUFFER_SET(host_availability_file, struct_peer->V_peer_availability_trace);
1911 SURFXML_BUFFER_SET(host_state_file, struct_peer->V_peer_state_trace);
1912 SURFXML_BUFFER_SET(host_coordinates, "");
1913 SURFXML_BUFFER_SET(host_core, "1.0");
1914 SURFXML_START_TAG(host);
1915 SURFXML_END_TAG(host);
1917 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->V_peer_coord);
1918 SURFXML_BUFFER_SET(router_id, router_id);
1919 SURFXML_BUFFER_SET(router_coordinates, struct_peer->V_peer_coord);
1920 SURFXML_START_TAG(router);
1921 SURFXML_END_TAG(router);
1923 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, struct_peer->V_peer_bw_in, struct_peer->V_peer_lat);
1924 A_surfxml_link_state = A_surfxml_link_state_ON;
1925 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1926 SURFXML_BUFFER_SET(link_id, link_id_up);
1927 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_in);
1928 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1929 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1930 SURFXML_BUFFER_SET(link_latency_file, "");
1931 SURFXML_BUFFER_SET(link_state_file, "");
1932 SURFXML_START_TAG(link);
1933 SURFXML_END_TAG(link);
1935 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, struct_peer->V_peer_bw_out, struct_peer->V_peer_lat);
1936 A_surfxml_link_state = A_surfxml_link_state_ON;
1937 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1938 SURFXML_BUFFER_SET(link_id, link_id_down);
1939 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_out);
1940 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1941 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1942 SURFXML_BUFFER_SET(link_latency_file, "");
1943 SURFXML_BUFFER_SET(link_state_file, "");
1944 SURFXML_START_TAG(link);
1945 SURFXML_END_TAG(link);
1950 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1951 XBT_DEBUG("symmetrical=\"NO\">");
1952 SURFXML_BUFFER_SET(route_src, host_id);
1953 SURFXML_BUFFER_SET(route_dst, router_id);
1954 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1955 SURFXML_START_TAG(route);
1957 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1958 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1959 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1960 SURFXML_START_TAG(link_ctn);
1961 SURFXML_END_TAG(link_ctn);
1963 XBT_DEBUG("</route>");
1964 SURFXML_END_TAG(route);
1967 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1968 XBT_DEBUG("symmetrical=\"NO\">");
1969 SURFXML_BUFFER_SET(route_src, router_id);
1970 SURFXML_BUFFER_SET(route_dst, host_id);
1971 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1972 SURFXML_START_TAG(route);
1974 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
1975 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
1976 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1977 SURFXML_START_TAG(link_ctn);
1978 SURFXML_END_TAG(link_ctn);
1980 XBT_DEBUG("</route>");
1981 SURFXML_END_TAG(route);
1984 SURFXML_END_TAG(AS);
1987 //xbt_dynar_free(&tab_elements_num);
1991 free(link_backbone);
1994 surfxml_bufferstack_pop(1);
1997 static void routing_parse_Srandom(void)
1999 double mean, std, min, max, seed;
2000 char *random_id = A_surfxml_random_id;
2001 char *random_radical = A_surfxml_random_radical;
2002 char *rd_name = NULL;
2004 mean = surf_parse_get_double(A_surfxml_random_mean);
2005 std = surf_parse_get_double(A_surfxml_random_std_deviation);
2006 min = surf_parse_get_double(A_surfxml_random_min);
2007 max = surf_parse_get_double(A_surfxml_random_max);
2008 seed = surf_parse_get_double(A_surfxml_random_seed);
2012 random_data_t random = xbt_new0(s_random_data_t, 1);
2015 xbt_dynar_t radical_elements;
2019 xbt_dynar_t radical_ends;
2021 random->generator = A_surfxml_random_generator;
2022 random->seed = seed;
2026 /* Check user stupidities */
2028 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2030 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2033 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2036 /* normalize the mean and standard deviation before storing */
2037 random->mean = (mean - min) / (max - min);
2038 random->std = std / (max - min);
2040 if (random->mean * (1 - random->mean) < random->std * random->std)
2041 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2042 random->mean, random->std);
2044 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2054 if(xbt_dict_size(random_value)==0)
2055 random_value = xbt_dict_new();
2057 if(!strcmp(random_radical,""))
2059 res = random_generate(random);
2060 rd_value = bprintf("%f",res);
2061 xbt_dict_set(random_value, random_id, rd_value, free);
2065 radical_elements = xbt_str_split(random_radical, ",");
2066 xbt_dynar_foreach(radical_elements, iter, groups) {
2067 radical_ends = xbt_str_split(groups, "-");
2068 switch (xbt_dynar_length(radical_ends)) {
2070 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2071 res = random_generate(random);
2072 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2073 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2078 start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
2079 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
2080 for (i = start; i <= end; i++) {
2081 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2082 res = random_generate(random);
2083 tmpbuf = bprintf("%s%d",random_id,i);
2084 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2089 XBT_INFO("Malformed radical");
2092 res = random_generate(random);
2093 rd_name = bprintf("%s_router",random_id);
2094 rd_value = bprintf("%f",res);
2095 xbt_dict_set(random_value, rd_name, rd_value, free);
2097 xbt_dynar_free(&radical_ends);
2100 xbt_dynar_free(&radical_elements);
2104 static void routing_parse_Erandom(void)
2106 /*xbt_dict_cursor_t cursor = NULL;
2110 xbt_dict_foreach(random_value, cursor, key, elem) {
2111 XBT_DEBUG("%s = %s",key,elem);
2117 * New methods to init the routing model component from the lua script
2122 * add a host to the network element list
2125 void routing_add_host(const char *host_id)
2127 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2131 * Set a new link on the actual list of link for a route or ASroute
2133 void routing_add_link(const char *link_id)
2135 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2139 *Set the endpoints for a route
2141 void routing_set_route(const char *src_id, const char *dst_id)
2143 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2147 * Store the route by calling parse_E_route_store_route
2149 void routing_store_route(void)
2151 parse_E_route_store_route();