1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <pcre.h> /* regular expression library */
8 #include "surf_routing_private.h"
9 #include "surf/surf_routing.h"
10 #include "surf/surfxml_parse_values.h"
13 int ROUTING_HOST_LEVEL; //Routing level
14 int SURF_CPU_LEVEL; //Surf cpu level
15 int SURF_WKS_LEVEL; //Surf workstation level
16 int SIMIX_HOST_LEVEL; //Simix level
17 int MSG_HOST_LEVEL; //Msg level
18 int SD_HOST_LEVEL; //Simdag level
19 int COORD_HOST_LEVEL; //Coordinates level
20 int NS3_HOST_LEVEL; //host node for ns3
23 int SD_LINK_LEVEL; //Simdag level
24 int SURF_LINK_LEVEL; //Surf level
25 int NS3_LINK_LEVEL; //link for ns3
27 xbt_lib_t as_router_lib;
28 int ROUTING_ASR_LEVEL; //Routing level
29 int COORD_ASR_LEVEL; //Coordinates level
30 int NS3_ASR_LEVEL; //host node for ns3
32 static xbt_dict_t patterns = NULL;
33 static xbt_dict_t random_value = NULL;
36 routing_global_t global_routing = NULL;
37 routing_component_t current_routing = NULL;
38 model_type_t current_routing_model = NULL;
40 /* global parse functions */
41 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
42 static const char *src = NULL; /* temporary store the source name of a route */
43 static const char *dst = NULL; /* temporary store the destination name of a route */
44 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
45 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
46 static double_f_cpvoid_t get_link_latency = NULL;
48 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
50 static void routing_parse_Speer(void); /* peer bypass */
51 static void routing_parse_Srandom(void); /* random bypass */
52 static void routing_parse_Erandom(void); /* random bypass */
54 static void routing_parse_Sconfig(void); /* config Tag */
55 static void routing_parse_Econfig(void); /* config Tag */
57 static char* replace_random_parameter(char * chaine);
58 static void clean_dict_random(void);
60 /* this lines are only for replace use like index in the model table */
65 SURF_MODEL_DIJKSTRACACHE,
70 struct s_model_type routing_models[] = { {"Full",
71 "Full routing data (fast, large memory requirements, fully expressive)",
77 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
78 model_floyd_create, model_floyd_load, model_floyd_unload,
81 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
82 model_dijkstra_create, model_dijkstra_both_load,
83 model_dijkstra_both_unload, model_dijkstra_both_end},
85 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
86 model_dijkstracache_create, model_dijkstra_both_load,
87 model_dijkstra_both_unload, model_dijkstra_both_end},
88 {"none", "No routing (usable with Constant network only)",
89 model_none_create, model_none_load, model_none_unload, model_none_end},
90 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
91 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
92 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
93 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
94 {NULL, NULL, NULL, NULL, NULL, NULL}
97 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
99 double src_coord, dst_coord;
101 src_coord = atof(xbt_dynar_get_as(src, index, char *));
102 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
104 return (src_coord-dst_coord)*(src_coord-dst_coord);
108 static double base_vivaldi_get_latency (const char *src, const char *dst)
110 double euclidean_dist;
111 xbt_dynar_t src_ctn, dst_ctn;
112 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
113 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
114 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
115 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
117 if(dst_ctn == NULL || src_ctn == NULL)
118 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
120 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
121 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
123 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
126 return euclidean_dist / 1000;
129 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
131 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
132 int need_to_clean = e_route?0:1;
134 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
135 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
136 if(need_to_clean) generic_free_extended_route(e_route);
139 return base_vivaldi_get_latency(src,dst);
144 * \brief Add a "host" to the network element list
146 static void parse_S_host(const char *host_id, const char* coord)
148 network_element_info_t info = NULL;
149 if (current_routing->hierarchy == SURF_ROUTING_NULL)
150 current_routing->hierarchy = SURF_ROUTING_BASE;
151 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
152 "Reading a host, processing unit \"%s\" already exists",
154 xbt_assert(current_routing->set_processing_unit,
155 "no defined method \"set_processing_unit\" in \"%s\"",
156 current_routing->name);
157 (*(current_routing->set_processing_unit)) (current_routing, host_id);
158 info = xbt_new0(s_network_element_info_t, 1);
159 info->rc_component = current_routing;
160 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
161 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
162 if (strcmp(coord,"")) {
163 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
164 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
165 xbt_dynar_shrink(ctn, 0);
166 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
170 static void parse_E_host(void)
172 xbt_dict_cursor_t cursor = NULL;
176 xbt_dict_foreach(current_property_set, cursor, key, elem) {
177 XBT_DEBUG("property : %s = %s",key,elem);
182 * \brief Add a host to the network element list from XML
184 static void parse_S_host_XML(void)
186 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
188 static void parse_E_host_XML(void)
194 * \brief Add a host to the network element list from lua script
196 static void parse_S_host_lua(const char *host_id, const char *coord)
198 parse_S_host(host_id, coord);
203 * \brief Add a "router" to the network element list
205 static void parse_S_router(const char *router_id)
207 network_element_info_t info = NULL;
209 if (current_routing->hierarchy == SURF_ROUTING_NULL)
210 current_routing->hierarchy = SURF_ROUTING_BASE;
211 xbt_assert(!xbt_lib_get_or_null(as_router_lib,A_surfxml_router_id, ROUTING_ASR_LEVEL),
212 "Reading a router, processing unit \"%s\" already exists",
214 xbt_assert(current_routing->set_processing_unit,
215 "no defined method \"set_processing_unit\" in \"%s\"",
216 current_routing->name);
217 (*(current_routing->set_processing_unit)) (current_routing,
219 info = xbt_new0(s_network_element_info_t, 1);
220 info->rc_component = current_routing;
221 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
223 xbt_lib_set(as_router_lib,router_id,ROUTING_ASR_LEVEL,(void *) info);
224 if (strcmp(A_surfxml_router_coordinates,"")) {
225 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
226 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
227 xbt_dynar_shrink(ctn, 0);
228 xbt_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn);
233 * brief Add a "router" to the network element list from XML description
235 static void parse_S_router_XML(void)
237 return parse_S_router(A_surfxml_router_id);
241 * brief Add a "router" to the network element list from XML description
243 static void parse_S_router_lua(const char* router_id)
245 return parse_S_router(router_id);
249 * \brief Set the endponints for a route
251 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
253 if (src != NULL && dst != NULL && link_list != NULL)
254 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
258 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
259 "Some limits are null in the route between \"%s\" and \"%s\"",
261 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
265 * \brief Set the endpoints for a route from XML
267 static void parse_S_route_new_and_endpoints_XML(void)
269 parse_S_route_new_and_endpoints(A_surfxml_route_src,
270 A_surfxml_route_dst);
274 * \brief Set the endpoints for a route from lua
276 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
278 parse_S_route_new_and_endpoints(id_src, id_dst);
282 * \brief Set the endponints and gateways for a ASroute
284 static void parse_S_ASroute_new_and_endpoints(void)
286 if (src != NULL && dst != NULL && link_list != NULL)
287 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
288 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
289 src = A_surfxml_ASroute_src;
290 dst = A_surfxml_ASroute_dst;
291 gw_src = A_surfxml_ASroute_gw_src;
292 gw_dst = A_surfxml_ASroute_gw_dst;
293 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
294 || strlen(gw_dst) > 0,
295 "Some limits are null in the route between \"%s\" and \"%s\"",
297 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
301 * \brief Set the endponints for a bypassRoute
303 static void parse_S_bypassRoute_new_and_endpoints(void)
305 if (src != NULL && dst != NULL && link_list != NULL)
307 "Bypass Route between %s to %s can not be defined",
308 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
309 src = A_surfxml_bypassRoute_src;
310 dst = A_surfxml_bypassRoute_dst;
311 gw_src = A_surfxml_bypassRoute_gw_src;
312 gw_dst = A_surfxml_bypassRoute_gw_dst;
313 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
314 || strlen(gw_dst) > 0,
315 "Some limits are null in the route between \"%s\" and \"%s\"",
317 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
321 * \brief Set a new link on the actual list of link for a route or ASroute
323 static void parse_E_link_ctn_new_elem(const char *link_id)
326 val = xbt_strdup(link_id);
327 xbt_dynar_push(link_list, &val);
331 * \brief Set a new link on the actual list of link for a route or ASroute from XML
334 static void parse_E_link_ctn_new_elem_XML(void)
336 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
337 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
338 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
339 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
340 parse_E_link_ctn_new_elem(link_id);
343 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
344 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
345 parse_E_link_ctn_new_elem(link_id);
351 * \brief Set a new link on the actual list of link for a route or ASroute from lua
353 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
355 parse_E_link_ctn_new_elem(link_id);
359 * \brief Store the route by calling the set_route function of the current routing component
361 static void parse_E_route_store_route(void)
363 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
364 route->generic_route.link_list = link_list;
365 xbt_assert(current_routing->set_route,
366 "no defined method \"set_route\" in \"%s\"",
367 current_routing->name);
368 (*(current_routing->set_route)) (current_routing, src, dst, route);
375 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
377 static void parse_E_ASroute_store_route(void)
379 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
380 e_route->generic_route.link_list = link_list;
381 e_route->src_gateway = xbt_strdup(gw_src);
382 e_route->dst_gateway = xbt_strdup(gw_dst);
383 xbt_assert(current_routing->set_ASroute,
384 "no defined method \"set_ASroute\" in \"%s\"",
385 current_routing->name);
386 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
395 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
397 static void parse_E_bypassRoute_store_route(void)
399 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
400 e_route->generic_route.link_list = link_list;
401 e_route->src_gateway = xbt_strdup(gw_src);
402 e_route->dst_gateway = xbt_strdup(gw_dst);
403 xbt_assert(current_routing->set_bypassroute,
404 "no defined method \"set_bypassroute\" in \"%s\"",
405 current_routing->name);
406 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
416 * \brief Make a new routing component
418 * make the new structure and
419 * set the parsing functions to allows parsing the part of the routing tree
421 static void parse_S_AS(char *AS_id, char *AS_routing)
423 routing_component_t new_routing;
424 model_type_t model = NULL;
425 char *wanted = AS_routing;
427 /* seach the routing model */
428 for (cpt = 0; routing_models[cpt].name; cpt++)
429 if (!strcmp(wanted, routing_models[cpt].name))
430 model = &routing_models[cpt];
431 /* if its not exist, error */
433 fprintf(stderr, "Routing model %s not found. Existing models:\n",
435 for (cpt = 0; routing_models[cpt].name; cpt++)
436 if (!strcmp(wanted, routing_models[cpt].name))
437 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
438 routing_models[cpt].desc);
442 /* make a new routing component */
443 new_routing = (routing_component_t) (*(model->create)) ();
444 new_routing->routing = model;
445 new_routing->hierarchy = SURF_ROUTING_NULL;
446 new_routing->name = xbt_strdup(AS_id);
447 new_routing->routing_sons = xbt_dict_new();
449 /* Hack for Vivaldi */
450 if(!strcmp(model->name,"Vivaldi"))
451 new_routing->get_latency = vivaldi_get_link_latency;
453 if (current_routing == NULL && global_routing->root == NULL) {
455 /* it is the first one */
456 new_routing->routing_father = NULL;
457 global_routing->root = new_routing;
459 } else if (current_routing != NULL && global_routing->root != NULL) {
461 xbt_assert(!xbt_dict_get_or_null
462 (current_routing->routing_sons, AS_id),
463 "The AS \"%s\" already exists", AS_id);
464 /* it is a part of the tree */
465 new_routing->routing_father = current_routing;
466 /* set the father behavior */
467 if (current_routing->hierarchy == SURF_ROUTING_NULL)
468 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
469 /* add to the sons dictionary */
470 xbt_dict_set(current_routing->routing_sons, AS_id,
471 (void *) new_routing, NULL);
472 /* add to the father element list */
473 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
474 /* unload the prev parse rules */
475 (*(current_routing->routing->unload)) ();
478 THROWF(arg_error, 0, "All defined components must be belong to a AS");
480 /* set the new parse rules */
481 (*(new_routing->routing->load)) ();
482 /* set the new current component of the tree */
483 current_routing = new_routing;
487 * Detect the routing model type of the routing component from XML platforms
489 static void parse_S_AS_XML(void)
491 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
495 * define the routing model type of routing component from lua script
497 static void parse_S_AS_lua(char *id, char *mode)
499 parse_S_AS(id, mode);
504 * \brief Finish the creation of a new routing component
506 * When you finish to read the routing component, other structures must be created.
507 * the "end" method allow to do that for any routing model type
509 static void parse_E_AS(const char *AS_id)
512 if (current_routing == NULL) {
513 THROWF(arg_error, 0, "Close AS(%s), that never open", AS_id);
515 network_element_info_t info = NULL;
516 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
517 "The AS \"%s\" already exists",current_routing->name);
518 info = xbt_new0(s_network_element_info_t, 1);
519 info->rc_component = current_routing->routing_father;
520 info->rc_type = SURF_NETWORK_ELEMENT_AS;
521 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
523 (*(current_routing->routing->unload)) ();
524 (*(current_routing->routing->end)) ();
525 current_routing = current_routing->routing_father;
526 if (current_routing != NULL)
527 (*(current_routing->routing->load)) ();
532 * \brief Finish the creation of a new routing component from XML
534 static void parse_E_AS_XML(void)
536 parse_E_AS(A_surfxml_AS_id);
540 * \brief Finish the creation of a new routing component from lua
542 static void parse_E_AS_lua(const char *id)
547 /* Aux Business methods */
550 * \brief Get the AS name of the element
552 * \param name the host name
555 static char* elements_As_name(const char *name)
557 routing_component_t as_comp;
559 /* (1) find the as where the host is located */
560 as_comp = ((network_element_info_t)
561 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
562 return as_comp->name;
567 * \brief Get the AS father and the first elements of the chain
569 * \param src the source host name
570 * \param dst the destination host name
572 * Get the common father of the to processing units, and the first different
573 * father in the chain
575 static void elements_father(const char *src, const char *dst,
576 routing_component_t *res_father,
577 routing_component_t *res_src,
578 routing_component_t *res_dst)
580 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
581 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
582 routing_component_t src_as, dst_as;
583 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
584 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
587 routing_component_t current;
588 routing_component_t current_src;
589 routing_component_t current_dst;
590 routing_component_t father;
592 /* (1) find the as where the src and dst are located */
593 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
595 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
598 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
600 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
601 src_as = src_data->rc_component;
602 dst_as = dst_data->rc_component;
604 xbt_assert(src_as && dst_as,
605 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
607 /* (2) find the path to the root routing component */
608 for (current = src_as ; current != NULL ; current = current->routing_father) {
609 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
610 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
611 path_src[index_src++] = current;
613 for (current = dst_as ; current != NULL ; current = current->routing_father) {
614 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
615 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
616 path_dst[index_dst++] = current;
619 /* (3) find the common father */
621 current_src = path_src[--index_src];
622 current_dst = path_dst[--index_dst];
623 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
625 /* (4) they are not in the same routing component, make the path */
626 if (current_src == current_dst)
627 father = current_src;
629 father = path_src[index_src + 1];
631 /* (5) result generation */
632 *res_father = father; /* first the common father of src and dst */
633 *res_src = current_src; /* second the first different father of src */
634 *res_dst = current_dst; /* three the first different father of dst */
636 #undef ELEMENTS_FATHER_MAXDEPTH
639 /* Global Business methods */
642 * \brief Recursive function for get_route_latency
644 * \param src the source host name
645 * \param dst the destination host name
646 * \param *e_route the route where the links are stored
647 * \param *latency the latency, if needed
649 * This function is called by "get_route" and "get_latency". It allows to walk
650 * recursively through the routing components tree.
652 static void _get_route_latency(const char *src, const char *dst,
653 xbt_dynar_t *route, double *latency)
655 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
656 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
658 routing_component_t common_father;
659 routing_component_t src_father;
660 routing_component_t dst_father;
661 elements_father(src, dst, &common_father, &src_father, &dst_father);
663 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
665 route_extended_t e_route = NULL;
667 e_route = common_father->get_route(common_father, src, dst);
668 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
669 *route = e_route->generic_route.link_list;
672 *latency = common_father->get_latency(common_father, src, dst, e_route);
673 xbt_assert(*latency >= 0.0,
674 "latency error on route between \"%s\" and \"%s\"", src, dst);
677 xbt_free(e_route->src_gateway);
678 xbt_free(e_route->dst_gateway);
682 } else { /* SURF_ROUTING_RECURSIVE */
684 route_extended_t e_route_bypass = NULL;
685 if (common_father->get_bypass_route)
686 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
688 xbt_assert(!latency || !e_route_bypass,
689 "Bypass cannot work yet with get_latency");
691 route_extended_t e_route_cnt = e_route_bypass
693 : common_father->get_route(common_father,
694 src_father->name, dst_father->name);
696 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
697 src_father->name, dst_father->name);
699 xbt_assert((e_route_cnt->src_gateway == NULL) ==
700 (e_route_cnt->dst_gateway == NULL),
701 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
704 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
707 *latency = common_father->get_latency(common_father,
708 src_father->name, dst_father->name,
710 xbt_assert(*latency >= 0.0,
711 "latency error on route between \"%s\" and \"%s\"",
712 src_father->name, dst_father->name);
718 if (strcmp(src, e_route_cnt->src_gateway)) {
720 xbt_dynar_t route_src;
722 _get_route_latency(src, e_route_cnt->src_gateway,
723 (route ? &route_src : NULL),
724 (latency ? &latency_src : NULL));
726 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
727 src, e_route_cnt->src_gateway);
728 xbt_dynar_foreach(route_src, cpt, link) {
729 xbt_dynar_push(*route, &link);
731 xbt_dynar_free(&route_src);
734 xbt_assert(latency_src >= 0.0,
735 "latency error on route between \"%s\" and \"%s\"",
736 src, e_route_cnt->src_gateway);
737 *latency += latency_src;
742 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
743 xbt_dynar_push(*route, &link);
747 if (strcmp(e_route_cnt->dst_gateway, dst)) {
749 xbt_dynar_t route_dst;
751 _get_route_latency(e_route_cnt->dst_gateway, dst,
752 (route ? &route_dst : NULL),
753 (latency ? &latency_dst : NULL));
755 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
756 e_route_cnt->dst_gateway, dst);
757 xbt_dynar_foreach(route_dst, cpt, link) {
758 xbt_dynar_push(*route, &link);
760 xbt_dynar_free(&route_dst);
763 xbt_assert(latency_dst >= 0.0,
764 "latency error on route between \"%s\" and \"%s\"",
765 e_route_cnt->dst_gateway, dst);
766 *latency += latency_dst;
770 generic_free_extended_route(e_route_cnt);
775 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
777 static void get_route_latency(const char *src, const char *dst,
778 xbt_dynar_t *route, double *latency, int cleanup)
780 _get_route_latency(src, dst, route, latency);
781 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
782 xbt_assert(!latency || *latency >= 0.0,
783 "latency error on route between \"%s\" and \"%s\"", src, dst);
785 xbt_dynar_free(&global_routing->last_route);
786 global_routing->last_route = cleanup ? *route : NULL;
791 * \brief Generic method: find a route between hosts
793 * \param src the source host name
794 * \param dst the destination host name
796 * walk through the routing components tree and find a route between hosts
797 * by calling the differents "get_route" functions in each routing component.
798 * No need to free the returned dynar. It will be freed at the next call.
800 static xbt_dynar_t get_route(const char *src, const char *dst)
802 xbt_dynar_t route = NULL;
803 get_route_latency(src, dst, &route, NULL, 1);
808 * \brief Generic method: find a route between hosts
810 * \param src the source host name
811 * \param dst the destination host name
813 * same as get_route, but return NULL if any exception is raised.
815 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
817 xbt_dynar_t route = NULL;
820 get_route_latency(src, dst, &route, NULL, 1);
822 xbt_ex_free(exception);
829 * \brief Generic method: find a route between hosts
831 * \param src the source host name
832 * \param dst the destination host name
834 * walk through the routing components tree and find a route between hosts
835 * by calling the differents "get_route" functions in each routing component.
836 * Leaves the caller the responsability to clean the returned dynar.
838 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
840 xbt_dynar_t route = NULL;
841 get_route_latency(src, dst, &route, NULL, 0);
846 static double get_latency(const char *src, const char *dst)
848 double latency = -1.0;
849 get_route_latency(src, dst, NULL, &latency, 0);
854 * \brief Recursive function for finalize
856 * \param rc the source host name
858 * This fuction is call by "finalize". It allow to finalize the
859 * AS or routing components. It delete all the structures.
861 static void _finalize(routing_component_t rc)
864 xbt_dict_cursor_t cursor = NULL;
866 routing_component_t elem;
867 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
870 xbt_dict_t tmp_sons = rc->routing_sons;
871 char *tmp_name = rc->name;
872 xbt_dict_free(&tmp_sons);
874 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
875 current_routing->name);
876 (*(rc->finalize)) (rc);
881 * \brief Generic method: delete all the routing structures
883 * walk through the routing components tree and delete the structures
884 * by calling the differents "finalize" functions in each routing component
886 static void finalize(void)
888 /* delete recursibly all the tree */
889 _finalize(global_routing->root);
890 /* delete last_route */
891 xbt_dynar_free(&(global_routing->last_route));
892 /* delete global routing structure */
893 xbt_free(global_routing);
896 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
898 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
900 //adding my one link routes
903 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
905 xbt_dynar_foreach(onelink_mine, cpt, link) {
906 xbt_dynar_push(ret, &link);
911 xbt_dict_cursor_t cursor = NULL;
912 routing_component_t rc_child;
913 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
914 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
916 xbt_dynar_foreach(onelink_child, cpt, link) {
917 xbt_dynar_push(ret, &link);
924 static xbt_dynar_t get_onelink_routes(void)
926 return recursive_get_onelink_routes(global_routing->root);
929 e_surf_network_element_type_t get_network_element_type(const char
932 network_element_info_t rc = NULL;
934 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
935 if(rc) return rc->rc_type;
937 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
938 if(rc) return rc->rc_type;
940 return SURF_NETWORK_ELEMENT_NULL;
944 * \brief Generic method: create the global routing schema
946 * Make a global routing structure and set all the parsing functions.
948 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
950 /* config the uniq global routing */
951 global_routing = xbt_new0(s_routing_global_t, 1);
952 global_routing->root = NULL;
953 global_routing->get_route = get_route;
954 global_routing->get_route_or_null = get_route_or_null;
955 global_routing->get_latency = get_latency;
956 global_routing->get_route_no_cleanup = get_route_no_cleanup;
957 global_routing->get_onelink_routes = get_onelink_routes;
958 global_routing->get_route_latency = get_route_latency;
959 global_routing->get_network_element_type = get_network_element_type;
960 global_routing->finalize = finalize;
961 global_routing->loopback = loopback;
962 global_routing->size_of_link = size_of_links;
963 global_routing->last_route = NULL;
964 get_link_latency = get_link_latency_fun;
965 /* no current routing at moment */
966 current_routing = NULL;
968 /* parse generic elements */
969 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
970 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
971 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
973 surfxml_add_callback(STag_surfxml_route_cb_list,
974 &parse_S_route_new_and_endpoints_XML);
975 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
976 &parse_S_ASroute_new_and_endpoints);
977 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
978 &parse_S_bypassRoute_new_and_endpoints);
980 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
981 &parse_E_link_ctn_new_elem_XML);
983 surfxml_add_callback(ETag_surfxml_route_cb_list,
984 &parse_E_route_store_route);
985 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
986 &parse_E_ASroute_store_route);
987 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
988 &parse_E_bypassRoute_store_route);
990 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
991 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
993 surfxml_add_callback(STag_surfxml_cluster_cb_list,
994 &routing_parse_Scluster);
996 surfxml_add_callback(STag_surfxml_peer_cb_list,
997 &routing_parse_Speer);
999 surfxml_add_callback(ETag_surfxml_platform_cb_list,
1000 &clean_dict_random);
1003 instr_routing_define_callbacks();
1007 void surf_parse_add_callback_config(void)
1009 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1010 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1011 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1012 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
1013 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1016 void surf_parse_models_setup()
1018 routing_parse_Erandom();
1019 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1020 surf_config_models_setup(platform_filename);
1021 free(platform_filename);
1024 /* ************************************************** */
1025 /* ********** PATERN FOR NEW ROUTING **************** */
1027 /* The minimal configuration of a new routing model need the next functions,
1028 * also you need to set at the start of the file, the new model in the model
1029 * list. Remember keep the null ending of the list.
1031 /*** Routing model structure ***/
1033 // s_routing_component_t generic_routing;
1034 // /* things that your routing model need */
1035 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1037 /*** Parse routing model functions ***/
1038 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1039 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1040 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1041 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1042 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1044 /*** Business methods ***/
1045 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1046 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1047 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1049 /*** Creation routing model functions ***/
1050 // static void* model_NEW_create(void) {
1051 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1052 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1053 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1054 // new_component->generic_routing.set_route = model_NEW_set_route;
1055 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1056 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1057 // new_component->generic_routing.get_route = NEW_get_route;
1058 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1059 // new_component->generic_routing.finalize = NEW_finalize;
1060 // /* initialization of internal structures */
1061 // return new_component;
1062 // } /* mandatory */
1063 // static void model_NEW_load(void) {} /* mandatory */
1064 // static void model_NEW_unload(void) {} /* mandatory */
1065 // static void model_NEW_end(void) {} /* mandatory */
1067 /* ************************************************************************** */
1068 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1070 void generic_set_processing_unit(routing_component_t rc,
1073 XBT_DEBUG("Load process unit \"%s\"", name);
1074 int *id = xbt_new0(int, 1);
1075 xbt_dict_t _to_index;
1076 _to_index = current_routing->to_index;
1077 *id = xbt_dict_length(_to_index);
1078 xbt_dict_set(_to_index, name, id, xbt_free);
1081 void generic_set_autonomous_system(routing_component_t rc,
1084 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1085 int *id = xbt_new0(int, 1);
1086 xbt_dict_t _to_index;
1087 _to_index = current_routing->to_index;
1088 *id = xbt_dict_length(_to_index);
1089 xbt_dict_set(_to_index, name, id, xbt_free);
1092 int surf_pointer_resource_cmp(const void *a, const void *b)
1097 int surf_link_resource_cmp(const void *a, const void *b)
1099 return !!memcmp(a,b,global_routing->size_of_link);
1102 void generic_set_bypassroute(routing_component_t rc,
1103 const char *src, const char *dst,
1104 route_extended_t e_route)
1106 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1107 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1110 route_name = bprintf("%s#%s", src, dst);
1111 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1112 "Invalid count of links, must be greater than zero (%s,%s)",
1114 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1115 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1116 src, e_route->src_gateway, dst, e_route->dst_gateway);
1118 route_extended_t new_e_route =
1119 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1120 xbt_dynar_free(&(e_route->generic_route.link_list));
1123 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1124 (void (*)(void *)) generic_free_extended_route);
1125 xbt_free(route_name);
1128 /* ************************************************************************** */
1129 /* *********************** GENERIC BUSINESS METHODS ************************* */
1131 double generic_get_link_latency(routing_component_t rc,
1132 const char *src, const char *dst,
1133 route_extended_t route)
1135 int need_to_clean = route?0:1;
1138 double latency = 0.0;
1140 route = route?route:rc->get_route(rc,src,dst);
1142 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1143 latency += get_link_latency(link);
1145 if(need_to_clean) generic_free_extended_route(route);
1149 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1151 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1154 route_extended_t generic_get_bypassroute(routing_component_t rc,
1158 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1159 routing_component_t src_as, dst_as;
1160 int index_src, index_dst;
1161 xbt_dynar_t path_src = NULL;
1162 xbt_dynar_t path_dst = NULL;
1163 routing_component_t current = NULL;
1164 routing_component_t *current_src = NULL;
1165 routing_component_t *current_dst = NULL;
1167 /* (1) find the as where the src and dst are located */
1168 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1169 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1170 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1171 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1173 if(src_data == NULL || dst_data == NULL)
1174 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1175 src, dst, rc->name);
1177 src_as = ((network_element_info_t)src_data)->rc_component;
1178 dst_as = ((network_element_info_t)dst_data)->rc_component;
1180 /* (2) find the path to the root routing component */
1181 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1183 while (current != NULL) {
1184 xbt_dynar_push(path_src, ¤t);
1185 current = current->routing_father;
1187 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1189 while (current != NULL) {
1190 xbt_dynar_push(path_dst, ¤t);
1191 current = current->routing_father;
1194 /* (3) find the common father */
1195 index_src = path_src->used - 1;
1196 index_dst = path_dst->used - 1;
1197 current_src = xbt_dynar_get_ptr(path_src, index_src);
1198 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1199 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1200 xbt_dynar_pop_ptr(path_src);
1201 xbt_dynar_pop_ptr(path_dst);
1204 current_src = xbt_dynar_get_ptr(path_src, index_src);
1205 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1208 int max_index_src = path_src->used - 1;
1209 int max_index_dst = path_dst->used - 1;
1211 int max_index = max(max_index_src, max_index_dst);
1214 route_extended_t e_route_bypass = NULL;
1216 for (max = 0; max <= max_index; max++) {
1217 for (i = 0; i < max; i++) {
1218 if (i <= max_index_src && max <= max_index_dst) {
1219 char *route_name = bprintf("%s#%s",
1220 (*(routing_component_t *)
1222 (path_src, i)))->name,
1223 (*(routing_component_t *)
1225 (path_dst, max)))->name);
1227 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1228 xbt_free(route_name);
1232 if (max <= max_index_src && i <= max_index_dst) {
1233 char *route_name = bprintf("%s#%s",
1234 (*(routing_component_t *)
1236 (path_src, max)))->name,
1237 (*(routing_component_t *)
1239 (path_dst, i)))->name);
1241 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1242 xbt_free(route_name);
1251 if (max <= max_index_src && max <= max_index_dst) {
1252 char *route_name = bprintf("%s#%s",
1253 (*(routing_component_t *)
1255 (path_src, max)))->name,
1256 (*(routing_component_t *)
1258 (path_dst, max)))->name);
1259 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1260 xbt_free(route_name);
1266 xbt_dynar_free(&path_src);
1267 xbt_dynar_free(&path_dst);
1269 route_extended_t new_e_route = NULL;
1271 if (e_route_bypass) {
1273 unsigned int cpt = 0;
1274 new_e_route = xbt_new0(s_route_extended_t, 1);
1275 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1276 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1277 new_e_route->generic_route.link_list =
1278 xbt_dynar_new(global_routing->size_of_link, NULL);
1279 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1280 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1287 /* ************************************************************************** */
1288 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1291 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1292 void *data, int order)
1298 xbt_dynar_t links = NULL, links_id = NULL;
1300 new_route = xbt_new0(s_route_t, 1);
1301 new_route->link_list =
1302 xbt_dynar_new(global_routing->size_of_link, NULL);
1304 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1305 "the hierarchy type is not SURF_ROUTING_BASE");
1307 links = ((route_t) data)->link_list;
1310 links_id = new_route->link_list;
1312 xbt_dynar_foreach(links, cpt, link_name) {
1315 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1318 xbt_dynar_push(links_id, &link);
1320 xbt_dynar_unshift(links_id, &link);
1322 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1329 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1330 void *data, int order)
1334 route_extended_t e_route, new_e_route;
1337 xbt_dynar_t links = NULL, links_id = NULL;
1339 new_e_route = xbt_new0(s_route_extended_t, 1);
1340 new_e_route->generic_route.link_list =
1341 xbt_dynar_new(global_routing->size_of_link, NULL);
1342 new_e_route->src_gateway = NULL;
1343 new_e_route->dst_gateway = NULL;
1345 xbt_assert(hierarchy == SURF_ROUTING_BASE
1346 || hierarchy == SURF_ROUTING_RECURSIVE,
1347 "the hierarchy type is not defined");
1349 if (hierarchy == SURF_ROUTING_BASE) {
1351 route = (route_t) data;
1352 links = route->link_list;
1354 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1356 e_route = (route_extended_t) data;
1357 xbt_assert(e_route->src_gateway
1358 && e_route->dst_gateway, "bad gateway, is null");
1359 links = e_route->generic_route.link_list;
1361 /* remeber not erase the gateway names */
1362 new_e_route->src_gateway = strdup(e_route->src_gateway);
1363 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1366 links_id = new_e_route->generic_route.link_list;
1368 xbt_dynar_foreach(links, cpt, link_name) {
1371 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1374 xbt_dynar_push(links_id, &link);
1376 xbt_dynar_unshift(links_id, &link);
1378 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1384 void generic_free_route(route_t route)
1387 xbt_dynar_free(&(route->link_list));
1392 void generic_free_extended_route(route_extended_t e_route)
1395 xbt_dynar_free(&(e_route->generic_route.link_list));
1396 if (e_route->src_gateway)
1397 xbt_free(e_route->src_gateway);
1398 if (e_route->dst_gateway)
1399 xbt_free(e_route->dst_gateway);
1404 static routing_component_t generic_as_exist(routing_component_t find_from,
1405 routing_component_t to_find)
1407 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1408 xbt_dict_cursor_t cursor = NULL;
1411 routing_component_t elem;
1412 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1413 if (to_find == elem || generic_as_exist(elem, to_find)) {
1424 generic_autonomous_system_exist(routing_component_t rc, char *element)
1426 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1427 routing_component_t element_as, result, elem;
1428 xbt_dict_cursor_t cursor = NULL;
1430 element_as = ((network_element_info_t)
1431 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1432 result = ((routing_component_t) - 1);
1433 if (element_as != rc)
1434 result = generic_as_exist(rc, element_as);
1438 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1439 found = !strcmp(elem->name, element);
1450 generic_processing_units_exist(routing_component_t rc, char *element)
1452 routing_component_t element_as;
1453 element_as = ((network_element_info_t)
1454 xbt_lib_get_or_null(host_lib,
1455 element, ROUTING_HOST_LEVEL))->rc_component;
1456 if (element_as == rc)
1458 return generic_as_exist(rc, element_as);
1461 void generic_src_dst_check(routing_component_t rc, const char *src,
1465 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1466 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1467 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1468 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1470 if(src_data == NULL || dst_data == NULL)
1471 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1472 src, dst, rc->name);
1474 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1475 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1477 if(src_as != dst_as)
1478 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1479 src, src_as->name, dst, dst_as->name);
1481 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1482 src,dst,src_as->name, dst_as->name,rc->name);
1485 static void routing_parse_Sconfig(void)
1487 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1490 static void routing_parse_Econfig(void)
1492 xbt_dict_cursor_t cursor = NULL;
1496 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1497 cfg = bprintf("%s:%s",key,elem);
1498 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1499 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1501 XBT_INFO("The custom configuration '%s' is already define by user!",key);
1504 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1507 void routing_parse_Scluster(void)
1509 static int AX_ptr = 0;
1511 char *cluster_id = A_surfxml_cluster_id;
1512 char *cluster_prefix = A_surfxml_cluster_prefix;
1513 char *cluster_suffix = A_surfxml_cluster_suffix;
1514 char *cluster_radical = A_surfxml_cluster_radical;
1515 char *cluster_core = A_surfxml_cluster_core;
1516 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1517 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1518 char *cluster_power = xbt_strdup(A_surfxml_cluster_power);
1519 char *cluster_bw = xbt_strdup(A_surfxml_cluster_bw);
1520 char *cluster_lat = xbt_strdup(A_surfxml_cluster_lat);
1521 char *host_id, *groups, *link_id = NULL;
1522 char *router_id = xbt_strdup(A_surfxml_cluster_router_id);
1523 char *availability_file = xbt_strdup(A_surfxml_cluster_availability_file);
1524 char *state_file = xbt_strdup(A_surfxml_cluster_state_file);
1526 if(xbt_dict_size(patterns)==0)
1527 patterns = xbt_dict_new();
1529 xbt_dict_set(patterns,"id",cluster_id,NULL);
1530 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
1531 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
1533 cluster_power = replace_random_parameter(cluster_power);
1534 cluster_bw = replace_random_parameter(cluster_bw);
1535 cluster_lat = replace_random_parameter(cluster_lat);
1537 char *route_src_dst;
1540 xbt_dynar_t radical_elements;
1541 xbt_dynar_t radical_ends;
1542 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
1543 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
1545 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1546 static unsigned int surfxml_buffer_stack_stack[1024];
1548 surfxml_buffer_stack_stack[0] = 0;
1550 surfxml_bufferstack_push(1);
1552 SURFXML_BUFFER_SET(AS_id, cluster_id);
1553 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
1554 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
1555 SURFXML_START_TAG(AS);
1557 radical_elements = xbt_str_split(cluster_radical, ",");
1558 xbt_dynar_foreach(radical_elements, iter, groups) {
1559 radical_ends = xbt_str_split(groups, "-");
1560 switch (xbt_dynar_length(radical_ends)) {
1562 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
1563 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
1564 link_id = bprintf("%s_link_%d", cluster_id, start);
1565 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1566 A_surfxml_host_state = A_surfxml_host_state_ON;
1568 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, cluster_power);
1569 SURFXML_BUFFER_SET(host_id, host_id);
1570 SURFXML_BUFFER_SET(host_power, cluster_power);
1572 if(!strcmp(A_surfxml_cluster_availability_file,"")){
1573 char* tmp_availability_file = xbt_strdup(availability_file);
1574 xbt_str_varsubst(tmp_availability_file,patterns);
1575 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1576 SURFXML_BUFFER_SET(host_availability_file, tmp_availability_file);
1577 xbt_free(tmp_availability_file);
1581 XBT_DEBUG("\tavailability_file=\"\"");
1582 SURFXML_BUFFER_SET(host_availability_file, "");
1584 if(!strcmp(A_surfxml_cluster_state_file,"")){
1585 char *tmp_state_file = xbt_strdup(state_file);
1586 xbt_str_varsubst(tmp_state_file,patterns);
1587 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1588 SURFXML_BUFFER_SET(host_state_file, tmp_state_file);
1589 xbt_free(tmp_state_file);
1593 XBT_DEBUG("\tstate_file=\"\"");
1594 SURFXML_BUFFER_SET(host_state_file, "");
1597 SURFXML_BUFFER_SET(host_core, cluster_core);
1598 SURFXML_BUFFER_SET(host_availability, "1.0");
1599 SURFXML_BUFFER_SET(host_coordinates, "");
1600 SURFXML_START_TAG(host);
1601 SURFXML_END_TAG(host);
1602 XBT_DEBUG("</host>");
1604 A_surfxml_link_state = A_surfxml_link_state_ON;
1605 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1606 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1607 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1608 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1609 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1611 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
1613 SURFXML_BUFFER_SET(link_id, link_id);
1614 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
1615 SURFXML_BUFFER_SET(link_latency, cluster_lat);
1616 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1617 SURFXML_BUFFER_SET(link_latency_file, "");
1618 SURFXML_BUFFER_SET(link_state_file, "");
1619 SURFXML_START_TAG(link);
1620 SURFXML_END_TAG(link);
1628 surf_parse_get_int(&start,
1629 xbt_dynar_get_as(radical_ends, 0, char *));
1630 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1631 for (i = start; i <= end; i++) {
1632 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
1633 link_id = bprintf("%s_link_%d", cluster_id, i);
1634 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1635 A_surfxml_host_state = A_surfxml_host_state_ON;
1637 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, cluster_power);
1638 SURFXML_BUFFER_SET(host_id, host_id);
1639 SURFXML_BUFFER_SET(host_power, cluster_power);
1641 if(!strcmp(A_surfxml_cluster_availability_file,"")){
1642 char* tmp_availability_file = xbt_strdup(availability_file);
1643 xbt_str_varsubst(tmp_availability_file,patterns);
1644 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1645 SURFXML_BUFFER_SET(host_availability_file, tmp_availability_file);
1646 xbt_free(tmp_availability_file);
1650 XBT_DEBUG("\tavailability_file=\"\"");
1651 SURFXML_BUFFER_SET(host_availability_file, "");
1653 if(!strcmp(A_surfxml_cluster_state_file,"")){
1654 char *tmp_state_file = xbt_strdup(state_file);
1655 xbt_str_varsubst(tmp_state_file,patterns);
1656 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1657 SURFXML_BUFFER_SET(host_state_file, tmp_state_file);
1658 xbt_free(tmp_state_file);
1662 XBT_DEBUG("\tstate_file=\"\"");
1663 SURFXML_BUFFER_SET(host_state_file, "");
1666 SURFXML_BUFFER_SET(host_core, cluster_core);
1667 SURFXML_BUFFER_SET(host_availability, "1.0");
1668 SURFXML_BUFFER_SET(host_coordinates, "");
1669 SURFXML_START_TAG(host);
1670 SURFXML_END_TAG(host);
1671 XBT_DEBUG("</host>");
1673 A_surfxml_link_state = A_surfxml_link_state_ON;
1674 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1675 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1676 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1677 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1678 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1680 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
1682 SURFXML_BUFFER_SET(link_id, link_id);
1683 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
1684 SURFXML_BUFFER_SET(link_latency, cluster_lat);
1685 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1686 SURFXML_BUFFER_SET(link_latency_file, "");
1687 SURFXML_BUFFER_SET(link_state_file, "");
1688 SURFXML_START_TAG(link);
1689 SURFXML_END_TAG(link);
1697 XBT_DEBUG("Malformed radical");
1701 xbt_dynar_free(&radical_ends);
1703 xbt_dynar_free(&radical_elements);
1706 if(!strcmp(router_id,""))
1707 router_id = bprintf("%s%s_router%s", cluster_prefix, cluster_id, cluster_suffix);
1709 XBT_DEBUG("<router id=\"%s\"/>", router_id);
1710 SURFXML_BUFFER_SET(router_id, router_id);
1711 SURFXML_BUFFER_SET(router_coordinates, "");
1712 SURFXML_START_TAG(router);
1713 SURFXML_END_TAG(router);
1715 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1716 char *link_backbone = bprintf("%s_backbone", cluster_id);
1717 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
1718 A_surfxml_link_state = A_surfxml_link_state_ON;
1719 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1720 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1721 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1722 SURFXML_BUFFER_SET(link_id, link_backbone);
1723 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
1724 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
1725 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1726 SURFXML_BUFFER_SET(link_latency_file, "");
1727 SURFXML_BUFFER_SET(link_state_file, "");
1728 SURFXML_START_TAG(link);
1729 SURFXML_END_TAG(link);
1730 free(link_backbone);
1735 char *new_suffix = xbt_strdup("");
1737 radical_elements = xbt_str_split(cluster_suffix, ".");
1738 xbt_dynar_foreach(radical_elements, iter, groups) {
1739 if (strcmp(groups, "")) {
1740 char *old_suffix = new_suffix;
1741 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1745 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
1746 xbt_dynar_free(&radical_elements);
1747 xbt_free(new_suffix);
1749 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
1750 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
1751 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
1753 //from router to router
1754 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, router_id);
1755 XBT_DEBUG("symmetrical=\"NO\">");
1756 SURFXML_BUFFER_SET(route_src, router_id);
1757 SURFXML_BUFFER_SET(route_dst, router_id);
1758 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1759 SURFXML_START_TAG(route);
1761 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1762 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1763 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1764 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1765 SURFXML_START_TAG(link_ctn);
1766 SURFXML_END_TAG(link_ctn);
1769 XBT_DEBUG("</route>");
1770 SURFXML_END_TAG(route);
1772 //from host to router
1773 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, router_id);
1774 XBT_DEBUG("symmetrical=\"NO\">");
1775 SURFXML_BUFFER_SET(route_src, route_src_dst);
1776 SURFXML_BUFFER_SET(route_dst, router_id);
1777 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1778 SURFXML_START_TAG(route);
1780 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1781 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1782 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1783 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1784 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1785 SURFXML_START_TAG(link_ctn);
1786 SURFXML_END_TAG(link_ctn);
1788 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1789 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1790 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1791 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1792 SURFXML_START_TAG(link_ctn);
1793 SURFXML_END_TAG(link_ctn);
1796 XBT_DEBUG("</route>");
1797 SURFXML_END_TAG(route);
1799 //from router to host
1800 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, route_src_dst);
1801 XBT_DEBUG("symmetrical=\"NO\">");
1802 SURFXML_BUFFER_SET(route_src, router_id);
1803 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1804 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1805 SURFXML_START_TAG(route);
1807 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1808 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1809 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1810 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1811 SURFXML_START_TAG(link_ctn);
1812 SURFXML_END_TAG(link_ctn);
1815 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1816 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1817 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1818 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1819 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1820 SURFXML_START_TAG(link_ctn);
1821 SURFXML_END_TAG(link_ctn);
1823 XBT_DEBUG("</route>");
1824 SURFXML_END_TAG(route);
1827 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
1828 XBT_DEBUG("symmetrical=\"NO\">");
1829 SURFXML_BUFFER_SET(route_src, route_src_dst);
1830 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1831 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1832 SURFXML_START_TAG(route);
1834 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1835 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1836 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1837 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1838 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1839 SURFXML_START_TAG(link_ctn);
1840 SURFXML_END_TAG(link_ctn);
1842 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1843 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1844 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1845 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1846 SURFXML_START_TAG(link_ctn);
1847 SURFXML_END_TAG(link_ctn);
1850 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1851 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1852 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1853 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1854 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1855 SURFXML_START_TAG(link_ctn);
1856 SURFXML_END_TAG(link_ctn);
1858 XBT_DEBUG("</route>");
1859 SURFXML_END_TAG(route);
1861 free(pcre_link_dst);
1862 free(pcre_link_backbone);
1863 free(pcre_link_src);
1864 free(route_src_dst);
1866 xbt_free(cluster_bw);
1867 xbt_free(cluster_lat);
1868 xbt_free(cluster_power);
1869 xbt_free(availability_file);
1870 xbt_free(state_file);
1872 xbt_free(router_id);
1873 xbt_dict_free(&patterns);
1876 SURFXML_END_TAG(AS);
1879 surfxml_bufferstack_pop(1);
1882 * This function take a string and replace parameters from patterns dict.
1883 * It returns the new value.
1885 static char* replace_random_parameter(char * string)
1887 char *test_string = NULL;
1889 if(xbt_dict_size(random_value)==0)
1892 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1893 test_string = bprintf("${%s}", string);
1894 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1896 if (strcmp(test_string,"")) { //if not empty, keep this value.
1898 string = test_string;
1899 } //In other case take old value (without ${})
1905 static void clean_dict_random(void)
1907 xbt_dict_free(&random_value);
1908 xbt_dict_free(&patterns);
1911 static void routing_parse_Speer(void)
1913 static int AX_ptr = 0;
1915 char *peer_id = A_surfxml_peer_id;
1916 char *peer_power = A_surfxml_peer_power;
1917 char *peer_bw_in = A_surfxml_peer_bw_in;
1918 char *peer_bw_out = A_surfxml_peer_bw_out;
1919 char *peer_lat = A_surfxml_peer_lat;
1920 char *peer_coord = A_surfxml_peer_coordinates;
1921 char *peer_state_file = A_surfxml_peer_state_file;
1922 char *peer_availability_file = A_surfxml_peer_availability_file;
1924 char *host_id = NULL;
1925 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1927 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1928 static unsigned int surfxml_buffer_stack_stack[1024];
1930 surfxml_buffer_stack_stack[0] = 0;
1932 surfxml_bufferstack_push(1);
1934 SURFXML_BUFFER_SET(AS_id, peer_id);
1936 SURFXML_BUFFER_SET(AS_routing, "Full");
1937 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
1939 SURFXML_START_TAG(AS);
1942 host_id = bprintf("peer_%s", peer_id);
1943 router_id = bprintf("router_%s", peer_id);
1944 link_id_up = bprintf("link_%s_up", peer_id);
1945 link_id_down = bprintf("link_%s_down", peer_id);
1947 link_router = bprintf("%s_link_router", peer_id);
1948 link_backbone = bprintf("%s_backbone", peer_id);
1950 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
1951 A_surfxml_host_state = A_surfxml_host_state_ON;
1952 SURFXML_BUFFER_SET(host_id, host_id);
1953 SURFXML_BUFFER_SET(host_power, peer_power);
1954 SURFXML_BUFFER_SET(host_availability, "1.0");
1955 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
1956 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
1957 SURFXML_BUFFER_SET(host_coordinates, "");
1958 SURFXML_BUFFER_SET(host_core, "1.0");
1959 SURFXML_START_TAG(host);
1960 SURFXML_END_TAG(host);
1962 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
1963 SURFXML_BUFFER_SET(router_id, router_id);
1964 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
1965 SURFXML_START_TAG(router);
1966 SURFXML_END_TAG(router);
1968 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
1969 A_surfxml_link_state = A_surfxml_link_state_ON;
1970 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1971 SURFXML_BUFFER_SET(link_id, link_id_up);
1972 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
1973 SURFXML_BUFFER_SET(link_latency, peer_lat);
1974 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1975 SURFXML_BUFFER_SET(link_latency_file, "");
1976 SURFXML_BUFFER_SET(link_state_file, "");
1977 SURFXML_START_TAG(link);
1978 SURFXML_END_TAG(link);
1980 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
1981 A_surfxml_link_state = A_surfxml_link_state_ON;
1982 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1983 SURFXML_BUFFER_SET(link_id, link_id_down);
1984 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
1985 SURFXML_BUFFER_SET(link_latency, peer_lat);
1986 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1987 SURFXML_BUFFER_SET(link_latency_file, "");
1988 SURFXML_BUFFER_SET(link_state_file, "");
1989 SURFXML_START_TAG(link);
1990 SURFXML_END_TAG(link);
1995 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1996 XBT_DEBUG("symmetrical=\"NO\">");
1997 SURFXML_BUFFER_SET(route_src, host_id);
1998 SURFXML_BUFFER_SET(route_dst, router_id);
1999 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2000 SURFXML_START_TAG(route);
2002 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
2003 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
2004 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2005 SURFXML_START_TAG(link_ctn);
2006 SURFXML_END_TAG(link_ctn);
2008 XBT_DEBUG("</route>");
2009 SURFXML_END_TAG(route);
2012 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
2013 XBT_DEBUG("symmetrical=\"NO\">");
2014 SURFXML_BUFFER_SET(route_src, router_id);
2015 SURFXML_BUFFER_SET(route_dst, host_id);
2016 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2017 SURFXML_START_TAG(route);
2019 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
2020 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
2021 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2022 SURFXML_START_TAG(link_ctn);
2023 SURFXML_END_TAG(link_ctn);
2025 XBT_DEBUG("</route>");
2026 SURFXML_END_TAG(route);
2029 SURFXML_END_TAG(AS);
2032 //xbt_dynar_free(&tab_elements_num);
2036 free(link_backbone);
2039 surfxml_bufferstack_pop(1);
2042 static void routing_parse_Srandom(void)
2044 double mean, std, min, max, seed;
2045 char *random_id = A_surfxml_random_id;
2046 char *random_radical = A_surfxml_random_radical;
2047 char *rd_name = NULL;
2049 surf_parse_get_double(&mean,A_surfxml_random_mean);
2050 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2051 surf_parse_get_double(&min,A_surfxml_random_min);
2052 surf_parse_get_double(&max,A_surfxml_random_max);
2053 surf_parse_get_double(&seed,A_surfxml_random_seed);
2057 random_data_t random = xbt_new0(s_random_data_t, 1);
2060 xbt_dynar_t radical_elements;
2064 xbt_dynar_t radical_ends;
2066 random->generator = A_surfxml_random_generator;
2067 random->seed = seed;
2071 /* Check user stupidities */
2073 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2075 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2078 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2081 /* normalize the mean and standard deviation before storing */
2082 random->mean = (mean - min) / (max - min);
2083 random->std = std / (max - min);
2085 if (random->mean * (1 - random->mean) < random->std * random->std)
2086 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2087 random->mean, random->std);
2089 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2099 if(xbt_dict_size(random_value)==0)
2100 random_value = xbt_dict_new();
2102 if(!strcmp(random_radical,""))
2104 res = random_generate(random);
2105 rd_value = bprintf("%f",res);
2106 xbt_dict_set(random_value, random_id, rd_value, free);
2110 radical_elements = xbt_str_split(random_radical, ",");
2111 xbt_dynar_foreach(radical_elements, iter, groups) {
2112 radical_ends = xbt_str_split(groups, "-");
2113 switch (xbt_dynar_length(radical_ends)) {
2115 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2116 res = random_generate(random);
2117 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2118 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2122 case 2: surf_parse_get_int(&start,
2123 xbt_dynar_get_as(radical_ends, 0, char *));
2124 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2125 for (i = start; i <= end; i++) {
2126 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2127 res = random_generate(random);
2128 tmpbuf = bprintf("%s%d",random_id,i);
2129 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2134 XBT_INFO("Malformed radical");
2137 res = random_generate(random);
2138 rd_name = bprintf("%s_router",random_id);
2139 rd_value = bprintf("%f",res);
2140 xbt_dict_set(random_value, rd_name, rd_value, free);
2142 xbt_dynar_free(&radical_ends);
2145 xbt_dynar_free(&radical_elements);
2149 static void routing_parse_Erandom(void)
2151 xbt_dict_cursor_t cursor = NULL;
2155 xbt_dict_foreach(random_value, cursor, key, elem) {
2156 XBT_DEBUG("%s = %s",key,elem);
2163 * New methods to init the routing model component from the lua script
2167 * calling parse_S_AS_lua with lua values
2169 void routing_AS_init(const char *AS_id, const char *AS_routing)
2171 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
2175 * calling parse_E_AS_lua to fisnish the creation of routing component
2177 void routing_AS_end(const char *AS_id)
2179 parse_E_AS_lua((char *) AS_id);
2183 * add a host to the network element list
2186 void routing_add_host(const char *host_id)
2188 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2192 * Set a new link on the actual list of link for a route or ASroute
2194 void routing_add_link(const char *link_id)
2196 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2200 *Set the endpoints for a route
2202 void routing_set_route(const char *src_id, const char *dst_id)
2204 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2208 * Store the route by calling parse_E_route_store_route
2210 void routing_store_route(void)
2212 parse_E_route_store_route();