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"
12 int ROUTING_HOST_LEVEL; //Routing level
13 int SURF_CPU_LEVEL; //Surf cpu level
14 int SURF_WKS_LEVEL; //Surf workstation level
15 int SIMIX_HOST_LEVEL; //Simix level
16 int MSG_HOST_LEVEL; //Msg level
17 int SD_HOST_LEVEL; //Simdag level
18 int COORD_HOST_LEVEL; //Coordinates level
19 int NS3_HOST_LEVEL; //host node for ns3
22 int SD_LINK_LEVEL; //Simdag level
23 int SURF_LINK_LEVEL; //Surf level
24 int NS3_LINK_LEVEL; //link for ns3
26 xbt_lib_t as_router_lib;
27 int ROUTING_ASR_LEVEL; //Routing level
28 int COORD_ASR_LEVEL; //Coordinates level
29 int NS3_ASR_LEVEL; //host node for ns3
31 static xbt_dict_t patterns = NULL;
32 static xbt_dict_t random_value = NULL;
35 routing_global_t global_routing = NULL;
36 routing_component_t current_routing = NULL;
37 model_type_t current_routing_model = NULL;
39 /* global parse functions */
40 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
41 static const char *src = NULL; /* temporary store the source name of a route */
42 static const char *dst = NULL; /* temporary store the destination name of a route */
43 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
44 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
45 static double_f_cpvoid_t get_link_latency = NULL;
47 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
49 static void routing_parse_Speer(void); /* peer bypass */
50 static void routing_parse_Srandom(void); /* random bypass */
51 static void routing_parse_Erandom(void); /* random bypass */
53 static void routing_parse_Sconfig(void); /* config Tag */
54 static void routing_parse_Econfig(void); /* config Tag */
56 static char* replace_random_parameter(char * chaine);
57 static void clean_dict_random(void);
59 /* this lines are only for replace use like index in the model table */
64 SURF_MODEL_DIJKSTRACACHE,
69 struct s_model_type routing_models[] = { {"Full",
70 "Full routing data (fast, large memory requirements, fully expressive)",
76 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
77 model_floyd_create, model_floyd_load, model_floyd_unload,
80 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
81 model_dijkstra_create, model_dijkstra_both_load,
82 model_dijkstra_both_unload, model_dijkstra_both_end},
84 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
85 model_dijkstracache_create, model_dijkstra_both_load,
86 model_dijkstra_both_unload, model_dijkstra_both_end},
87 {"none", "No routing (usable with Constant network only)",
88 model_none_create, model_none_load, model_none_unload, model_none_end},
89 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
90 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
91 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
92 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
93 {NULL, NULL, NULL, NULL, NULL, NULL}
96 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
98 double src_coord, dst_coord;
100 src_coord = atof(xbt_dynar_get_as(src, index, char *));
101 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
103 return (src_coord-dst_coord)*(src_coord-dst_coord);
107 static double base_vivaldi_get_latency (const char *src, const char *dst)
109 double euclidean_dist;
110 xbt_dynar_t src_ctn, dst_ctn;
111 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
112 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
113 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
114 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
116 if(dst_ctn == NULL || src_ctn == NULL)
117 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
119 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
120 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
122 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
125 return euclidean_dist / 1000;
128 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
130 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
131 int need_to_clean = e_route?0:1;
133 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
134 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
135 if(need_to_clean) generic_free_extended_route(e_route);
138 return base_vivaldi_get_latency(src,dst);
143 * \brief Add a "host" to the network element list
145 static void parse_S_host(const char *host_id, const char* coord)
147 network_element_info_t info = NULL;
148 if (current_routing->hierarchy == SURF_ROUTING_NULL)
149 current_routing->hierarchy = SURF_ROUTING_BASE;
150 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
151 "Reading a host, processing unit \"%s\" already exists",
153 xbt_assert(current_routing->set_processing_unit,
154 "no defined method \"set_processing_unit\" in \"%s\"",
155 current_routing->name);
156 (*(current_routing->set_processing_unit)) (current_routing, host_id);
157 info = xbt_new0(s_network_element_info_t, 1);
158 info->rc_component = current_routing;
159 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
160 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
161 if (strcmp(coord,"")) {
162 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
163 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
164 xbt_dynar_shrink(ctn, 0);
165 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
169 static void parse_E_host(void)
171 xbt_dict_cursor_t cursor = NULL;
175 xbt_dict_foreach(current_property_set, cursor, key, elem) {
176 XBT_DEBUG("property : %s = %s",key,elem);
181 * \brief Add a host to the network element list from XML
183 static void parse_S_host_XML(void)
185 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
187 static void parse_E_host_XML(void)
193 * \brief Add a host to the network element list from lua script
195 static void parse_S_host_lua(const char *host_id, const char *coord)
197 parse_S_host(host_id, coord);
202 * \brief Add a "router" to the network element list
204 static void parse_S_router(const char *router_id)
206 network_element_info_t info = NULL;
208 if (current_routing->hierarchy == SURF_ROUTING_NULL)
209 current_routing->hierarchy = SURF_ROUTING_BASE;
210 xbt_assert(!xbt_lib_get_or_null(as_router_lib,A_surfxml_router_id, ROUTING_ASR_LEVEL),
211 "Reading a router, processing unit \"%s\" already exists",
213 xbt_assert(current_routing->set_processing_unit,
214 "no defined method \"set_processing_unit\" in \"%s\"",
215 current_routing->name);
216 (*(current_routing->set_processing_unit)) (current_routing,
218 info = xbt_new0(s_network_element_info_t, 1);
219 info->rc_component = current_routing;
220 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
222 xbt_lib_set(as_router_lib,router_id,ROUTING_ASR_LEVEL,(void *) info);
223 if (strcmp(A_surfxml_router_coordinates,"")) {
224 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
225 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
226 xbt_dynar_shrink(ctn, 0);
227 xbt_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn);
232 * brief Add a "router" to the network element list from XML description
234 static void parse_S_router_XML(void)
236 return parse_S_router(A_surfxml_router_id);
240 * brief Add a "router" to the network element list from XML description
242 static void parse_S_router_lua(const char* router_id)
244 return parse_S_router(router_id);
248 * \brief Set the endponints for a route
250 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
252 if (src != NULL && dst != NULL && link_list != NULL)
253 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
257 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
258 "Some limits are null in the route between \"%s\" and \"%s\"",
260 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
264 * \brief Set the endpoints for a route from XML
266 static void parse_S_route_new_and_endpoints_XML(void)
268 parse_S_route_new_and_endpoints(A_surfxml_route_src,
269 A_surfxml_route_dst);
273 * \brief Set the endpoints for a route from lua
275 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
277 parse_S_route_new_and_endpoints(id_src, id_dst);
281 * \brief Set the endponints and gateways for a ASroute
283 static void parse_S_ASroute_new_and_endpoints(void)
285 if (src != NULL && dst != NULL && link_list != NULL)
286 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
287 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
288 src = A_surfxml_ASroute_src;
289 dst = A_surfxml_ASroute_dst;
290 gw_src = A_surfxml_ASroute_gw_src;
291 gw_dst = A_surfxml_ASroute_gw_dst;
292 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
293 || strlen(gw_dst) > 0,
294 "Some limits are null in the route between \"%s\" and \"%s\"",
296 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
300 * \brief Set the endponints for a bypassRoute
302 static void parse_S_bypassRoute_new_and_endpoints(void)
304 if (src != NULL && dst != NULL && link_list != NULL)
306 "Bypass Route between %s to %s can not be defined",
307 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
308 src = A_surfxml_bypassRoute_src;
309 dst = A_surfxml_bypassRoute_dst;
310 gw_src = A_surfxml_bypassRoute_gw_src;
311 gw_dst = A_surfxml_bypassRoute_gw_dst;
312 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
313 || strlen(gw_dst) > 0,
314 "Some limits are null in the route between \"%s\" and \"%s\"",
316 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
320 * \brief Set a new link on the actual list of link for a route or ASroute
322 static void parse_E_link_ctn_new_elem(const char *link_id)
325 val = xbt_strdup(link_id);
326 xbt_dynar_push(link_list, &val);
330 * \brief Set a new link on the actual list of link for a route or ASroute from XML
333 static void parse_E_link_ctn_new_elem_XML(void)
335 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
336 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
337 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
338 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
339 parse_E_link_ctn_new_elem(link_id);
342 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
343 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
344 parse_E_link_ctn_new_elem(link_id);
350 * \brief Set a new link on the actual list of link for a route or ASroute from lua
352 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
354 parse_E_link_ctn_new_elem(link_id);
358 * \brief Store the route by calling the set_route function of the current routing component
360 static void parse_E_route_store_route(void)
362 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
363 route->generic_route.link_list = link_list;
364 xbt_assert(current_routing->set_route,
365 "no defined method \"set_route\" in \"%s\"",
366 current_routing->name);
367 (*(current_routing->set_route)) (current_routing, src, dst, route);
374 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
376 static void parse_E_ASroute_store_route(void)
378 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
379 e_route->generic_route.link_list = link_list;
380 e_route->src_gateway = xbt_strdup(gw_src);
381 e_route->dst_gateway = xbt_strdup(gw_dst);
382 xbt_assert(current_routing->set_ASroute,
383 "no defined method \"set_ASroute\" in \"%s\"",
384 current_routing->name);
385 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
394 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
396 static void parse_E_bypassRoute_store_route(void)
398 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
399 e_route->generic_route.link_list = link_list;
400 e_route->src_gateway = xbt_strdup(gw_src);
401 e_route->dst_gateway = xbt_strdup(gw_dst);
402 xbt_assert(current_routing->set_bypassroute,
403 "no defined method \"set_bypassroute\" in \"%s\"",
404 current_routing->name);
405 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
415 * \brief Make a new routing component
417 * make the new structure and
418 * set the parsing functions to allows parsing the part of the routing tree
420 static void parse_S_AS(char *AS_id, char *AS_routing)
422 routing_component_t new_routing;
423 model_type_t model = NULL;
424 char *wanted = AS_routing;
426 /* seach the routing model */
427 for (cpt = 0; routing_models[cpt].name; cpt++)
428 if (!strcmp(wanted, routing_models[cpt].name))
429 model = &routing_models[cpt];
430 /* if its not exist, error */
432 fprintf(stderr, "Routing model %s not found. Existing models:\n",
434 for (cpt = 0; routing_models[cpt].name; cpt++)
435 if (!strcmp(wanted, routing_models[cpt].name))
436 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
437 routing_models[cpt].desc);
441 /* make a new routing component */
442 new_routing = (routing_component_t) (*(model->create)) ();
443 new_routing->routing = model;
444 new_routing->hierarchy = SURF_ROUTING_NULL;
445 new_routing->name = xbt_strdup(AS_id);
446 new_routing->routing_sons = xbt_dict_new();
448 /* Hack for Vivaldi */
449 if(!strcmp(model->name,"Vivaldi"))
450 new_routing->get_latency = vivaldi_get_link_latency;
452 if (current_routing == NULL && global_routing->root == NULL) {
454 /* it is the first one */
455 new_routing->routing_father = NULL;
456 global_routing->root = new_routing;
458 } else if (current_routing != NULL && global_routing->root != NULL) {
460 xbt_assert(!xbt_dict_get_or_null
461 (current_routing->routing_sons, AS_id),
462 "The AS \"%s\" already exists", AS_id);
463 /* it is a part of the tree */
464 new_routing->routing_father = current_routing;
465 /* set the father behavior */
466 if (current_routing->hierarchy == SURF_ROUTING_NULL)
467 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
468 /* add to the sons dictionary */
469 xbt_dict_set(current_routing->routing_sons, AS_id,
470 (void *) new_routing, NULL);
471 /* add to the father element list */
472 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
473 /* unload the prev parse rules */
474 (*(current_routing->routing->unload)) ();
477 THROWF(arg_error, 0, "All defined components must be belong to a AS");
479 /* set the new parse rules */
480 (*(new_routing->routing->load)) ();
481 /* set the new current component of the tree */
482 current_routing = new_routing;
486 * Detect the routing model type of the routing component from XML platforms
488 static void parse_S_AS_XML(void)
490 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
494 * define the routing model type of routing component from lua script
496 static void parse_S_AS_lua(char *id, char *mode)
498 parse_S_AS(id, mode);
503 * \brief Finish the creation of a new routing component
505 * When you finish to read the routing component, other structures must be created.
506 * the "end" method allow to do that for any routing model type
508 static void parse_E_AS(const char *AS_id)
511 if (current_routing == NULL) {
512 THROWF(arg_error, 0, "Close AS(%s), that never open", AS_id);
514 network_element_info_t info = NULL;
515 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
516 "The AS \"%s\" already exists",current_routing->name);
517 info = xbt_new0(s_network_element_info_t, 1);
518 info->rc_component = current_routing->routing_father;
519 info->rc_type = SURF_NETWORK_ELEMENT_AS;
520 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
522 (*(current_routing->routing->unload)) ();
523 (*(current_routing->routing->end)) ();
524 current_routing = current_routing->routing_father;
525 if (current_routing != NULL)
526 (*(current_routing->routing->load)) ();
531 * \brief Finish the creation of a new routing component from XML
533 static void parse_E_AS_XML(void)
535 parse_E_AS(A_surfxml_AS_id);
539 * \brief Finish the creation of a new routing component from lua
541 static void parse_E_AS_lua(const char *id)
546 /* Aux Business methods */
549 * \brief Get the AS name of the element
551 * \param name the host name
554 static char* elements_As_name(const char *name)
556 routing_component_t as_comp;
558 /* (1) find the as where the host is located */
559 as_comp = ((network_element_info_t)
560 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
561 return as_comp->name;
566 * \brief Get the AS father and the first elements of the chain
568 * \param src the source host name
569 * \param dst the destination host name
571 * Get the common father of the to processing units, and the first different
572 * father in the chain
574 static void elements_father(const char *src, const char *dst,
575 routing_component_t *res_father,
576 routing_component_t *res_src,
577 routing_component_t *res_dst)
579 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
580 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
581 routing_component_t src_as, dst_as;
582 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
583 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
586 routing_component_t current;
587 routing_component_t current_src;
588 routing_component_t current_dst;
589 routing_component_t father;
591 /* (1) find the as where the src and dst are located */
592 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
594 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
597 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
599 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
600 src_as = src_data->rc_component;
601 dst_as = dst_data->rc_component;
603 xbt_assert(src_as && dst_as,
604 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
606 /* (2) find the path to the root routing component */
607 for (current = src_as ; current != NULL ; current = current->routing_father) {
608 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
609 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
610 path_src[index_src++] = current;
612 for (current = dst_as ; current != NULL ; current = current->routing_father) {
613 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
614 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
615 path_dst[index_dst++] = current;
618 /* (3) find the common father */
620 current_src = path_src[--index_src];
621 current_dst = path_dst[--index_dst];
622 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
624 /* (4) they are not in the same routing component, make the path */
625 if (current_src == current_dst)
626 father = current_src;
628 father = path_src[index_src + 1];
630 /* (5) result generation */
631 *res_father = father; /* first the common father of src and dst */
632 *res_src = current_src; /* second the first different father of src */
633 *res_dst = current_dst; /* three the first different father of dst */
635 #undef ELEMENTS_FATHER_MAXDEPTH
638 /* Global Business methods */
641 * \brief Recursive function for get_route_latency
643 * \param src the source host name
644 * \param dst the destination host name
645 * \param *e_route the route where the links are stored
646 * \param *latency the latency, if needed
648 * This function is called by "get_route" and "get_latency". It allows to walk
649 * recursively through the routing components tree.
651 static void _get_route_latency(const char *src, const char *dst,
652 xbt_dynar_t *route, double *latency)
654 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
655 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
657 routing_component_t common_father;
658 routing_component_t src_father;
659 routing_component_t dst_father;
660 elements_father(src, dst, &common_father, &src_father, &dst_father);
662 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
664 route_extended_t e_route = NULL;
666 e_route = common_father->get_route(common_father, src, dst);
667 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
668 *route = e_route->generic_route.link_list;
671 *latency = common_father->get_latency(common_father, src, dst, e_route);
672 xbt_assert(*latency >= 0.0,
673 "latency error on route between \"%s\" and \"%s\"", src, dst);
676 xbt_free(e_route->src_gateway);
677 xbt_free(e_route->dst_gateway);
681 } else { /* SURF_ROUTING_RECURSIVE */
683 route_extended_t e_route_bypass = NULL;
684 if (common_father->get_bypass_route)
685 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
687 xbt_assert(!latency || !e_route_bypass,
688 "Bypass cannot work yet with get_latency");
690 route_extended_t e_route_cnt = e_route_bypass
692 : common_father->get_route(common_father,
693 src_father->name, dst_father->name);
695 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
696 src_father->name, dst_father->name);
698 xbt_assert((e_route_cnt->src_gateway == NULL) ==
699 (e_route_cnt->dst_gateway == NULL),
700 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
703 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
706 *latency = common_father->get_latency(common_father,
707 src_father->name, dst_father->name,
709 xbt_assert(*latency >= 0.0,
710 "latency error on route between \"%s\" and \"%s\"",
711 src_father->name, dst_father->name);
717 if (strcmp(src, e_route_cnt->src_gateway)) {
719 xbt_dynar_t route_src;
721 _get_route_latency(src, e_route_cnt->src_gateway,
722 (route ? &route_src : NULL),
723 (latency ? &latency_src : NULL));
725 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
726 src, e_route_cnt->src_gateway);
727 xbt_dynar_foreach(route_src, cpt, link) {
728 xbt_dynar_push(*route, &link);
730 xbt_dynar_free(&route_src);
733 xbt_assert(latency_src >= 0.0,
734 "latency error on route between \"%s\" and \"%s\"",
735 src, e_route_cnt->src_gateway);
736 *latency += latency_src;
741 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
742 xbt_dynar_push(*route, &link);
746 if (strcmp(e_route_cnt->dst_gateway, dst)) {
748 xbt_dynar_t route_dst;
750 _get_route_latency(e_route_cnt->dst_gateway, dst,
751 (route ? &route_dst : NULL),
752 (latency ? &latency_dst : NULL));
754 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
755 e_route_cnt->dst_gateway, dst);
756 xbt_dynar_foreach(route_dst, cpt, link) {
757 xbt_dynar_push(*route, &link);
759 xbt_dynar_free(&route_dst);
762 xbt_assert(latency_dst >= 0.0,
763 "latency error on route between \"%s\" and \"%s\"",
764 e_route_cnt->dst_gateway, dst);
765 *latency += latency_dst;
769 generic_free_extended_route(e_route_cnt);
774 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
776 static void get_route_latency(const char *src, const char *dst,
777 xbt_dynar_t *route, double *latency, int cleanup)
779 _get_route_latency(src, dst, route, latency);
780 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
781 xbt_assert(!latency || *latency >= 0.0,
782 "latency error on route between \"%s\" and \"%s\"", src, dst);
784 xbt_dynar_free(&global_routing->last_route);
785 global_routing->last_route = cleanup ? *route : NULL;
790 * \brief Generic method: find a route between hosts
792 * \param src the source host name
793 * \param dst the destination host name
795 * walk through the routing components tree and find a route between hosts
796 * by calling the differents "get_route" functions in each routing component.
797 * No need to free the returned dynar. It will be freed at the next call.
799 static xbt_dynar_t get_route(const char *src, const char *dst)
801 xbt_dynar_t route = NULL;
802 get_route_latency(src, dst, &route, NULL, 1);
807 * \brief Generic method: find a route between hosts
809 * \param src the source host name
810 * \param dst the destination host name
812 * same as get_route, but return NULL if any exception is raised.
814 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
816 xbt_dynar_t route = NULL;
819 get_route_latency(src, dst, &route, NULL, 1);
827 * \brief Generic method: find a route between hosts
829 * \param src the source host name
830 * \param dst the destination host name
832 * walk through the routing components tree and find a route between hosts
833 * by calling the differents "get_route" functions in each routing component.
834 * Leaves the caller the responsability to clean the returned dynar.
836 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
838 xbt_dynar_t route = NULL;
839 get_route_latency(src, dst, &route, NULL, 0);
844 static double get_latency(const char *src, const char *dst)
846 double latency = -1.0;
847 get_route_latency(src, dst, NULL, &latency, 0);
852 * \brief Recursive function for finalize
854 * \param rc the source host name
856 * This fuction is call by "finalize". It allow to finalize the
857 * AS or routing components. It delete all the structures.
859 static void _finalize(routing_component_t rc)
862 xbt_dict_cursor_t cursor = NULL;
864 routing_component_t elem;
865 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
868 xbt_dict_t tmp_sons = rc->routing_sons;
869 char *tmp_name = rc->name;
870 xbt_dict_free(&tmp_sons);
872 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
873 current_routing->name);
874 (*(rc->finalize)) (rc);
879 * \brief Generic method: delete all the routing structures
881 * walk through the routing components tree and delete the structures
882 * by calling the differents "finalize" functions in each routing component
884 static void finalize(void)
886 /* delete recursibly all the tree */
887 _finalize(global_routing->root);
888 /* delete last_route */
889 xbt_dynar_free(&(global_routing->last_route));
890 /* delete global routing structure */
891 xbt_free(global_routing);
894 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
896 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
898 //adding my one link routes
901 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
903 xbt_dynar_foreach(onelink_mine, cpt, link) {
904 xbt_dynar_push(ret, &link);
909 xbt_dict_cursor_t cursor = NULL;
910 routing_component_t rc_child;
911 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
912 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
914 xbt_dynar_foreach(onelink_child, cpt, link) {
915 xbt_dynar_push(ret, &link);
922 static xbt_dynar_t get_onelink_routes(void)
924 return recursive_get_onelink_routes(global_routing->root);
927 e_surf_network_element_type_t get_network_element_type(const char
930 network_element_info_t rc = NULL;
932 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
933 if(rc) return rc->rc_type;
935 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
936 if(rc) return rc->rc_type;
938 return SURF_NETWORK_ELEMENT_NULL;
942 * \brief Generic method: create the global routing schema
944 * Make a global routing structure and set all the parsing functions.
946 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
948 /* config the uniq global routing */
949 global_routing = xbt_new0(s_routing_global_t, 1);
950 global_routing->root = NULL;
951 global_routing->get_route = get_route;
952 global_routing->get_route_or_null = get_route_or_null;
953 global_routing->get_latency = get_latency;
954 global_routing->get_route_no_cleanup = get_route_no_cleanup;
955 global_routing->get_onelink_routes = get_onelink_routes;
956 global_routing->get_route_latency = get_route_latency;
957 global_routing->get_network_element_type = get_network_element_type;
958 global_routing->finalize = finalize;
959 global_routing->loopback = loopback;
960 global_routing->size_of_link = size_of_links;
961 global_routing->last_route = NULL;
962 get_link_latency = get_link_latency_fun;
963 /* no current routing at moment */
964 current_routing = NULL;
966 /* parse generic elements */
967 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
968 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
969 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
971 surfxml_add_callback(STag_surfxml_route_cb_list,
972 &parse_S_route_new_and_endpoints_XML);
973 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
974 &parse_S_ASroute_new_and_endpoints);
975 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
976 &parse_S_bypassRoute_new_and_endpoints);
978 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
979 &parse_E_link_ctn_new_elem_XML);
981 surfxml_add_callback(ETag_surfxml_route_cb_list,
982 &parse_E_route_store_route);
983 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
984 &parse_E_ASroute_store_route);
985 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
986 &parse_E_bypassRoute_store_route);
988 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
989 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
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,
1001 instr_routing_define_callbacks();
1005 void surf_parse_add_callback_config(void)
1007 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1008 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1009 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1010 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
1011 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1014 void surf_parse_models_setup()
1016 routing_parse_Erandom();
1017 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1018 surf_config_models_setup(platform_filename);
1019 free(platform_filename);
1022 /* ************************************************** */
1023 /* ********** PATERN FOR NEW ROUTING **************** */
1025 /* The minimal configuration of a new routing model need the next functions,
1026 * also you need to set at the start of the file, the new model in the model
1027 * list. Remember keep the null ending of the list.
1029 /*** Routing model structure ***/
1031 // s_routing_component_t generic_routing;
1032 // /* things that your routing model need */
1033 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1035 /*** Parse routing model functions ***/
1036 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1037 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1038 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1039 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1040 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1042 /*** Business methods ***/
1043 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1044 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1045 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1047 /*** Creation routing model functions ***/
1048 // static void* model_NEW_create(void) {
1049 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1050 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1051 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1052 // new_component->generic_routing.set_route = model_NEW_set_route;
1053 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1054 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1055 // new_component->generic_routing.get_route = NEW_get_route;
1056 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1057 // new_component->generic_routing.finalize = NEW_finalize;
1058 // /* initialization of internal structures */
1059 // return new_component;
1060 // } /* mandatory */
1061 // static void model_NEW_load(void) {} /* mandatory */
1062 // static void model_NEW_unload(void) {} /* mandatory */
1063 // static void model_NEW_end(void) {} /* mandatory */
1065 /* ************************************************************************** */
1066 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1068 void generic_set_processing_unit(routing_component_t rc,
1071 XBT_DEBUG("Load process unit \"%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 void generic_set_autonomous_system(routing_component_t rc,
1082 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1083 int *id = xbt_new0(int, 1);
1084 xbt_dict_t _to_index;
1085 _to_index = current_routing->to_index;
1086 *id = xbt_dict_length(_to_index);
1087 xbt_dict_set(_to_index, name, id, xbt_free);
1090 int surf_pointer_resource_cmp(const void *a, const void *b)
1095 int surf_link_resource_cmp(const void *a, const void *b)
1097 return !!memcmp(a,b,global_routing->size_of_link);
1100 void generic_set_bypassroute(routing_component_t rc,
1101 const char *src, const char *dst,
1102 route_extended_t e_route)
1104 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1105 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1108 route_name = bprintf("%s#%s", src, dst);
1109 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1110 "Invalid count of links, must be greater than zero (%s,%s)",
1112 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1113 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1114 src, e_route->src_gateway, dst, e_route->dst_gateway);
1116 route_extended_t new_e_route =
1117 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1118 xbt_dynar_free(&(e_route->generic_route.link_list));
1121 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1122 (void (*)(void *)) generic_free_extended_route);
1123 xbt_free(route_name);
1126 /* ************************************************************************** */
1127 /* *********************** GENERIC BUSINESS METHODS ************************* */
1129 double generic_get_link_latency(routing_component_t rc,
1130 const char *src, const char *dst,
1131 route_extended_t route)
1133 int need_to_clean = route?0:1;
1136 double latency = 0.0;
1138 route = route?route:rc->get_route(rc,src,dst);
1140 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1141 latency += get_link_latency(link);
1143 if(need_to_clean) generic_free_extended_route(route);
1147 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1149 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1152 route_extended_t generic_get_bypassroute(routing_component_t rc,
1156 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1157 routing_component_t src_as, dst_as;
1158 int index_src, index_dst;
1159 xbt_dynar_t path_src = NULL;
1160 xbt_dynar_t path_dst = NULL;
1161 routing_component_t current = NULL;
1162 routing_component_t *current_src = NULL;
1163 routing_component_t *current_dst = NULL;
1165 /* (1) find the as where the src and dst are located */
1166 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1167 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1168 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1169 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1171 if(src_data == NULL || dst_data == NULL)
1172 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1173 src, dst, rc->name);
1175 src_as = ((network_element_info_t)src_data)->rc_component;
1176 dst_as = ((network_element_info_t)dst_data)->rc_component;
1178 /* (2) find the path to the root routing component */
1179 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1181 while (current != NULL) {
1182 xbt_dynar_push(path_src, ¤t);
1183 current = current->routing_father;
1185 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1187 while (current != NULL) {
1188 xbt_dynar_push(path_dst, ¤t);
1189 current = current->routing_father;
1192 /* (3) find the common father */
1193 index_src = path_src->used - 1;
1194 index_dst = path_dst->used - 1;
1195 current_src = xbt_dynar_get_ptr(path_src, index_src);
1196 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1197 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1198 xbt_dynar_pop_ptr(path_src);
1199 xbt_dynar_pop_ptr(path_dst);
1202 current_src = xbt_dynar_get_ptr(path_src, index_src);
1203 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1206 int max_index_src = path_src->used - 1;
1207 int max_index_dst = path_dst->used - 1;
1209 int max_index = max(max_index_src, max_index_dst);
1212 route_extended_t e_route_bypass = NULL;
1214 for (max = 0; max <= max_index; max++) {
1215 for (i = 0; i < max; i++) {
1216 if (i <= max_index_src && max <= max_index_dst) {
1217 char *route_name = bprintf("%s#%s",
1218 (*(routing_component_t *)
1220 (path_src, i)))->name,
1221 (*(routing_component_t *)
1223 (path_dst, max)))->name);
1225 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1226 xbt_free(route_name);
1230 if (max <= max_index_src && i <= max_index_dst) {
1231 char *route_name = bprintf("%s#%s",
1232 (*(routing_component_t *)
1234 (path_src, max)))->name,
1235 (*(routing_component_t *)
1237 (path_dst, i)))->name);
1239 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1240 xbt_free(route_name);
1249 if (max <= max_index_src && max <= max_index_dst) {
1250 char *route_name = bprintf("%s#%s",
1251 (*(routing_component_t *)
1253 (path_src, max)))->name,
1254 (*(routing_component_t *)
1256 (path_dst, max)))->name);
1257 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1258 xbt_free(route_name);
1264 xbt_dynar_free(&path_src);
1265 xbt_dynar_free(&path_dst);
1267 route_extended_t new_e_route = NULL;
1269 if (e_route_bypass) {
1271 unsigned int cpt = 0;
1272 new_e_route = xbt_new0(s_route_extended_t, 1);
1273 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1274 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1275 new_e_route->generic_route.link_list =
1276 xbt_dynar_new(global_routing->size_of_link, NULL);
1277 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1278 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1285 /* ************************************************************************** */
1286 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1289 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1290 void *data, int order)
1296 xbt_dynar_t links = NULL, links_id = NULL;
1298 new_route = xbt_new0(s_route_t, 1);
1299 new_route->link_list =
1300 xbt_dynar_new(global_routing->size_of_link, NULL);
1302 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1303 "the hierarchy type is not SURF_ROUTING_BASE");
1305 links = ((route_t) data)->link_list;
1308 links_id = new_route->link_list;
1310 xbt_dynar_foreach(links, cpt, link_name) {
1313 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1316 xbt_dynar_push(links_id, &link);
1318 xbt_dynar_unshift(links_id, &link);
1320 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1327 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1328 void *data, int order)
1332 route_extended_t e_route, new_e_route;
1335 xbt_dynar_t links = NULL, links_id = NULL;
1337 new_e_route = xbt_new0(s_route_extended_t, 1);
1338 new_e_route->generic_route.link_list =
1339 xbt_dynar_new(global_routing->size_of_link, NULL);
1340 new_e_route->src_gateway = NULL;
1341 new_e_route->dst_gateway = NULL;
1343 xbt_assert(hierarchy == SURF_ROUTING_BASE
1344 || hierarchy == SURF_ROUTING_RECURSIVE,
1345 "the hierarchy type is not defined");
1347 if (hierarchy == SURF_ROUTING_BASE) {
1349 route = (route_t) data;
1350 links = route->link_list;
1352 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1354 e_route = (route_extended_t) data;
1355 xbt_assert(e_route->src_gateway
1356 && e_route->dst_gateway, "bad gateway, is null");
1357 links = e_route->generic_route.link_list;
1359 /* remeber not erase the gateway names */
1360 new_e_route->src_gateway = strdup(e_route->src_gateway);
1361 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1364 links_id = new_e_route->generic_route.link_list;
1366 xbt_dynar_foreach(links, cpt, link_name) {
1369 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1372 xbt_dynar_push(links_id, &link);
1374 xbt_dynar_unshift(links_id, &link);
1376 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1382 void generic_free_route(route_t route)
1385 xbt_dynar_free(&(route->link_list));
1390 void generic_free_extended_route(route_extended_t e_route)
1393 xbt_dynar_free(&(e_route->generic_route.link_list));
1394 if (e_route->src_gateway)
1395 xbt_free(e_route->src_gateway);
1396 if (e_route->dst_gateway)
1397 xbt_free(e_route->dst_gateway);
1402 static routing_component_t generic_as_exist(routing_component_t find_from,
1403 routing_component_t to_find)
1405 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1406 xbt_dict_cursor_t cursor = NULL;
1409 routing_component_t elem;
1410 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1411 if (to_find == elem || generic_as_exist(elem, to_find)) {
1422 generic_autonomous_system_exist(routing_component_t rc, char *element)
1424 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1425 routing_component_t element_as, result, elem;
1426 xbt_dict_cursor_t cursor = NULL;
1428 element_as = ((network_element_info_t)
1429 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1430 result = ((routing_component_t) - 1);
1431 if (element_as != rc)
1432 result = generic_as_exist(rc, element_as);
1436 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1437 found = !strcmp(elem->name, element);
1448 generic_processing_units_exist(routing_component_t rc, char *element)
1450 routing_component_t element_as;
1451 element_as = ((network_element_info_t)
1452 xbt_lib_get_or_null(host_lib,
1453 element, ROUTING_HOST_LEVEL))->rc_component;
1454 if (element_as == rc)
1456 return generic_as_exist(rc, element_as);
1459 void generic_src_dst_check(routing_component_t rc, const char *src,
1463 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1464 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1465 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1466 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1468 if(src_data == NULL || dst_data == NULL)
1469 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1470 src, dst, rc->name);
1472 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1473 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1475 if(src_as != dst_as)
1476 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1477 src, src_as->name, dst, dst_as->name);
1479 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1480 src,dst,src_as->name, dst_as->name,rc->name);
1483 static void routing_parse_Sconfig(void)
1485 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1488 static void routing_parse_Econfig(void)
1490 xbt_dict_cursor_t cursor = NULL;
1494 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1495 cfg = bprintf("%s:%s",key,elem);
1496 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1497 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1499 XBT_INFO("The custom configuration '%s' is already define by user!",key);
1502 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1505 void routing_parse_Scluster(void)
1507 static int AX_ptr = 0;
1509 char *cluster_id = A_surfxml_cluster_id;
1510 char *cluster_prefix = A_surfxml_cluster_prefix;
1511 char *cluster_suffix = A_surfxml_cluster_suffix;
1512 char *cluster_radical = A_surfxml_cluster_radical;
1513 char *cluster_power = A_surfxml_cluster_power;
1514 char *cluster_core = A_surfxml_cluster_core;
1515 char *cluster_bw = A_surfxml_cluster_bw;
1516 char *cluster_lat = A_surfxml_cluster_lat;
1517 char *temp_cluster_bw = NULL;
1518 char *temp_cluster_lat = NULL;
1519 char *temp_cluster_power = NULL;
1520 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1521 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1522 char *cluster_availability_file = A_surfxml_cluster_availability_file;
1523 char *cluster_state_file = A_surfxml_cluster_state_file;
1524 char *host_id, *groups, *link_id = NULL;
1525 char *router_id = xbt_strdup(A_surfxml_cluster_router_id);
1526 char *availability_file = xbt_strdup(cluster_availability_file);
1527 char *state_file = xbt_strdup(cluster_state_file);
1529 if(xbt_dict_size(patterns)==0)
1530 patterns = xbt_dict_new();
1532 xbt_dict_set(patterns,"id",cluster_id,NULL);
1533 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
1534 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
1536 char *route_src_dst;
1539 xbt_dynar_t radical_elements;
1540 xbt_dynar_t radical_ends;
1541 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
1542 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
1544 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1545 static unsigned int surfxml_buffer_stack_stack[1024];
1547 surfxml_buffer_stack_stack[0] = 0;
1549 surfxml_bufferstack_push(1);
1551 SURFXML_BUFFER_SET(AS_id, cluster_id);
1552 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
1553 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
1554 SURFXML_START_TAG(AS);
1556 radical_elements = xbt_str_split(cluster_radical, ",");
1557 xbt_dynar_foreach(radical_elements, iter, groups) {
1558 radical_ends = xbt_str_split(groups, "-");
1559 switch (xbt_dynar_length(radical_ends)) {
1561 surf_parse_get_int(&start,
1562 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);
1566 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1567 temp_cluster_power = xbt_strdup(cluster_power);
1568 temp_cluster_power = replace_random_parameter(temp_cluster_power);
1569 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1570 A_surfxml_host_state = A_surfxml_host_state_ON;
1571 SURFXML_BUFFER_SET(host_id, host_id);
1572 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1573 SURFXML_BUFFER_SET(host_core, cluster_core);
1574 SURFXML_BUFFER_SET(host_availability, "1.0");
1575 SURFXML_BUFFER_SET(host_coordinates, "");
1576 xbt_free(availability_file);
1577 availability_file = xbt_strdup(cluster_availability_file);
1578 xbt_free(state_file);
1579 state_file = xbt_strdup(cluster_state_file);
1580 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1581 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1582 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1583 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1584 XBT_DEBUG("</host>");
1585 SURFXML_START_TAG(host);
1586 SURFXML_END_TAG(host);
1589 temp_cluster_bw = xbt_strdup(cluster_bw);
1590 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1591 temp_cluster_lat = xbt_strdup(cluster_lat);
1592 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1593 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1594 A_surfxml_link_state = A_surfxml_link_state_ON;
1595 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1596 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1597 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1598 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1599 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1600 SURFXML_BUFFER_SET(link_id, link_id);
1601 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1602 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1603 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1604 SURFXML_BUFFER_SET(link_latency_file, "");
1605 SURFXML_BUFFER_SET(link_state_file, "");
1606 SURFXML_START_TAG(link);
1607 SURFXML_END_TAG(link);
1609 xbt_free(temp_cluster_bw);
1610 xbt_free(temp_cluster_lat);
1611 xbt_free(temp_cluster_power);
1618 surf_parse_get_int(&start,
1619 xbt_dynar_get_as(radical_ends, 0, char *));
1620 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1621 for (i = start; i <= end; i++) {
1622 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
1623 link_id = bprintf("%s_link_%d", cluster_id, i);
1625 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1626 temp_cluster_power = xbt_strdup(cluster_power);
1627 temp_cluster_power = replace_random_parameter(temp_cluster_power);
1628 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1629 A_surfxml_host_state = A_surfxml_host_state_ON;
1630 SURFXML_BUFFER_SET(host_id, host_id);
1631 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1632 SURFXML_BUFFER_SET(host_core, cluster_core);
1633 SURFXML_BUFFER_SET(host_availability, "1.0");
1634 SURFXML_BUFFER_SET(host_coordinates, "");
1635 xbt_free(availability_file);
1636 availability_file = xbt_strdup(cluster_availability_file);
1637 xbt_free(state_file);
1638 state_file = xbt_strdup(cluster_state_file);
1639 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1640 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1641 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1642 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1643 XBT_DEBUG("</host>");
1644 SURFXML_START_TAG(host);
1645 SURFXML_END_TAG(host);
1647 xbt_free(temp_cluster_power);
1649 temp_cluster_bw = xbt_strdup(cluster_bw);
1650 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1651 temp_cluster_lat = xbt_strdup(cluster_lat);
1652 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1653 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1654 A_surfxml_link_state = A_surfxml_link_state_ON;
1655 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1656 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1657 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1658 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1659 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1660 SURFXML_BUFFER_SET(link_id, link_id);
1661 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1662 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1663 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1664 SURFXML_BUFFER_SET(link_latency_file, "");
1665 SURFXML_BUFFER_SET(link_state_file, "");
1666 SURFXML_START_TAG(link);
1667 SURFXML_END_TAG(link);
1669 xbt_free(temp_cluster_bw);
1670 xbt_free(temp_cluster_lat);
1677 XBT_DEBUG("Malformed radical");
1680 xbt_dynar_free(&radical_ends);
1682 xbt_dynar_free(&radical_elements);
1685 if(!strcmp(router_id,""))
1686 router_id = bprintf("%s%s_router%s", cluster_prefix, cluster_id, cluster_suffix);
1688 XBT_DEBUG("<router id=\"%s\"/>", router_id);
1689 SURFXML_BUFFER_SET(router_id, router_id);
1690 SURFXML_BUFFER_SET(router_coordinates, "");
1691 SURFXML_START_TAG(router);
1692 SURFXML_END_TAG(router);
1694 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1695 char *link_backbone = bprintf("%s_backbone", cluster_id);
1696 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
1697 A_surfxml_link_state = A_surfxml_link_state_ON;
1698 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1699 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1700 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1701 SURFXML_BUFFER_SET(link_id, link_backbone);
1702 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
1703 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
1704 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1705 SURFXML_BUFFER_SET(link_latency_file, "");
1706 SURFXML_BUFFER_SET(link_state_file, "");
1707 SURFXML_START_TAG(link);
1708 SURFXML_END_TAG(link);
1709 free(link_backbone);
1714 char *new_suffix = xbt_strdup("");
1716 radical_elements = xbt_str_split(cluster_suffix, ".");
1717 xbt_dynar_foreach(radical_elements, iter, groups) {
1718 if (strcmp(groups, "")) {
1719 char *old_suffix = new_suffix;
1720 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1724 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
1725 xbt_dynar_free(&radical_elements);
1728 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
1729 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
1730 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
1732 //from router to router
1733 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, router_id);
1734 XBT_DEBUG("symmetrical=\"NO\">");
1735 SURFXML_BUFFER_SET(route_src, router_id);
1736 SURFXML_BUFFER_SET(route_dst, router_id);
1737 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1738 SURFXML_START_TAG(route);
1740 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1741 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1742 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1743 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1744 SURFXML_START_TAG(link_ctn);
1745 SURFXML_END_TAG(link_ctn);
1748 XBT_DEBUG("</route>");
1749 SURFXML_END_TAG(route);
1751 //from host to router
1752 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, router_id);
1753 XBT_DEBUG("symmetrical=\"NO\">");
1754 SURFXML_BUFFER_SET(route_src, route_src_dst);
1755 SURFXML_BUFFER_SET(route_dst, router_id);
1756 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1757 SURFXML_START_TAG(route);
1759 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1760 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1761 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1762 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1763 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1764 SURFXML_START_TAG(link_ctn);
1765 SURFXML_END_TAG(link_ctn);
1767 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1768 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1769 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1770 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1771 SURFXML_START_TAG(link_ctn);
1772 SURFXML_END_TAG(link_ctn);
1775 XBT_DEBUG("</route>");
1776 SURFXML_END_TAG(route);
1778 //from router to host
1779 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, route_src_dst);
1780 XBT_DEBUG("symmetrical=\"NO\">");
1781 SURFXML_BUFFER_SET(route_src, router_id);
1782 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1783 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1784 SURFXML_START_TAG(route);
1786 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1787 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1788 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1789 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1790 SURFXML_START_TAG(link_ctn);
1791 SURFXML_END_TAG(link_ctn);
1794 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1795 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1796 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1797 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1798 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1799 SURFXML_START_TAG(link_ctn);
1800 SURFXML_END_TAG(link_ctn);
1802 XBT_DEBUG("</route>");
1803 SURFXML_END_TAG(route);
1806 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
1807 XBT_DEBUG("symmetrical=\"NO\">");
1808 SURFXML_BUFFER_SET(route_src, route_src_dst);
1809 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1810 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1811 SURFXML_START_TAG(route);
1813 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1814 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1815 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1816 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1817 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1818 SURFXML_START_TAG(link_ctn);
1819 SURFXML_END_TAG(link_ctn);
1821 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1822 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1823 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1824 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1825 SURFXML_START_TAG(link_ctn);
1826 SURFXML_END_TAG(link_ctn);
1829 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1830 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1831 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1832 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1833 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1834 SURFXML_START_TAG(link_ctn);
1835 SURFXML_END_TAG(link_ctn);
1837 XBT_DEBUG("</route>");
1838 SURFXML_END_TAG(route);
1840 free(pcre_link_dst);
1841 free(pcre_link_backbone);
1842 free(pcre_link_src);
1843 free(route_src_dst);
1846 xbt_dict_free(&patterns);
1847 free(availability_file);
1851 SURFXML_END_TAG(AS);
1854 surfxml_bufferstack_pop(1);
1857 * This function take a string and replace parameters from patterns dict.
1858 * It returns the new value.
1860 static char* replace_random_parameter(char * string)
1862 char *test_string = NULL;
1864 if(xbt_dict_size(random_value)==0)
1867 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1868 test_string = bprintf("${%s}", string);
1869 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1871 if (strcmp(test_string,"")) { //if not empty, keep this value.
1873 string = test_string;
1874 } //In other case take old value (without ${})
1880 static void clean_dict_random(void)
1882 xbt_dict_free(&random_value);
1883 xbt_dict_free(&patterns);
1886 static void routing_parse_Speer(void)
1888 static int AX_ptr = 0;
1890 char *peer_id = A_surfxml_peer_id;
1891 char *peer_power = A_surfxml_peer_power;
1892 char *peer_bw_in = A_surfxml_peer_bw_in;
1893 char *peer_bw_out = A_surfxml_peer_bw_out;
1894 char *peer_lat = A_surfxml_peer_lat;
1895 char *peer_coord = A_surfxml_peer_coordinates;
1896 char *peer_state_file = A_surfxml_peer_state_file;
1897 char *peer_availability_file = A_surfxml_peer_availability_file;
1899 char *host_id = NULL;
1900 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1902 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1903 static unsigned int surfxml_buffer_stack_stack[1024];
1905 surfxml_buffer_stack_stack[0] = 0;
1907 surfxml_bufferstack_push(1);
1909 SURFXML_BUFFER_SET(AS_id, peer_id);
1911 SURFXML_BUFFER_SET(AS_routing, "Full");
1912 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
1914 SURFXML_START_TAG(AS);
1917 host_id = bprintf("peer_%s", peer_id);
1918 router_id = bprintf("router_%s", peer_id);
1919 link_id_up = bprintf("link_%s_up", peer_id);
1920 link_id_down = bprintf("link_%s_down", peer_id);
1922 link_router = bprintf("%s_link_router", peer_id);
1923 link_backbone = bprintf("%s_backbone", peer_id);
1925 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
1926 A_surfxml_host_state = A_surfxml_host_state_ON;
1927 SURFXML_BUFFER_SET(host_id, host_id);
1928 SURFXML_BUFFER_SET(host_power, peer_power);
1929 SURFXML_BUFFER_SET(host_availability, "1.0");
1930 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
1931 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
1932 SURFXML_BUFFER_SET(host_coordinates, "");
1933 SURFXML_START_TAG(host);
1934 SURFXML_END_TAG(host);
1936 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
1937 SURFXML_BUFFER_SET(router_id, router_id);
1938 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
1939 SURFXML_START_TAG(router);
1940 SURFXML_END_TAG(router);
1942 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
1943 A_surfxml_link_state = A_surfxml_link_state_ON;
1944 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1945 SURFXML_BUFFER_SET(link_id, link_id_up);
1946 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
1947 SURFXML_BUFFER_SET(link_latency, peer_lat);
1948 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1949 SURFXML_BUFFER_SET(link_latency_file, "");
1950 SURFXML_BUFFER_SET(link_state_file, "");
1951 SURFXML_START_TAG(link);
1952 SURFXML_END_TAG(link);
1954 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
1955 A_surfxml_link_state = A_surfxml_link_state_ON;
1956 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1957 SURFXML_BUFFER_SET(link_id, link_id_down);
1958 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
1959 SURFXML_BUFFER_SET(link_latency, peer_lat);
1960 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1961 SURFXML_BUFFER_SET(link_latency_file, "");
1962 SURFXML_BUFFER_SET(link_state_file, "");
1963 SURFXML_START_TAG(link);
1964 SURFXML_END_TAG(link);
1969 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1970 XBT_DEBUG("symmetrical=\"NO\">");
1971 SURFXML_BUFFER_SET(route_src, host_id);
1972 SURFXML_BUFFER_SET(route_dst, router_id);
1973 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1974 SURFXML_START_TAG(route);
1976 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1977 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1978 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1979 SURFXML_START_TAG(link_ctn);
1980 SURFXML_END_TAG(link_ctn);
1982 XBT_DEBUG("</route>");
1983 SURFXML_END_TAG(route);
1986 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1987 XBT_DEBUG("symmetrical=\"NO\">");
1988 SURFXML_BUFFER_SET(route_src, router_id);
1989 SURFXML_BUFFER_SET(route_dst, host_id);
1990 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1991 SURFXML_START_TAG(route);
1993 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
1994 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
1995 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1996 SURFXML_START_TAG(link_ctn);
1997 SURFXML_END_TAG(link_ctn);
1999 XBT_DEBUG("</route>");
2000 SURFXML_END_TAG(route);
2003 SURFXML_END_TAG(AS);
2006 //xbt_dynar_free(&tab_elements_num);
2010 free(link_backbone);
2013 surfxml_bufferstack_pop(1);
2016 static void routing_parse_Srandom(void)
2018 double mean, std, min, max, seed;
2019 char *random_id = A_surfxml_random_id;
2020 char *random_radical = A_surfxml_random_radical;
2021 char *rd_name = NULL;
2023 surf_parse_get_double(&mean,A_surfxml_random_mean);
2024 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2025 surf_parse_get_double(&min,A_surfxml_random_min);
2026 surf_parse_get_double(&max,A_surfxml_random_max);
2027 surf_parse_get_double(&seed,A_surfxml_random_seed);
2031 random_data_t random = xbt_new0(s_random_data_t, 1);
2034 xbt_dynar_t radical_elements;
2038 xbt_dynar_t radical_ends;
2040 random->generator = A_surfxml_random_generator;
2041 random->seed = seed;
2045 /* Check user stupidities */
2047 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2049 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2052 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2055 /* normalize the mean and standard deviation before storing */
2056 random->mean = (mean - min) / (max - min);
2057 random->std = std / (max - min);
2059 if (random->mean * (1 - random->mean) < random->std * random->std)
2060 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2061 random->mean, random->std);
2063 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2073 if(xbt_dict_size(random_value)==0)
2074 random_value = xbt_dict_new();
2076 if(!strcmp(random_radical,""))
2078 res = random_generate(random);
2079 rd_value = bprintf("%f",res);
2080 xbt_dict_set(random_value, random_id, rd_value, free);
2084 radical_elements = xbt_str_split(random_radical, ",");
2085 xbt_dynar_foreach(radical_elements, iter, groups) {
2086 radical_ends = xbt_str_split(groups, "-");
2087 switch (xbt_dynar_length(radical_ends)) {
2089 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2090 res = random_generate(random);
2091 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2092 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2096 case 2: surf_parse_get_int(&start,
2097 xbt_dynar_get_as(radical_ends, 0, char *));
2098 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2099 for (i = start; i <= end; i++) {
2100 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2101 res = random_generate(random);
2102 tmpbuf = bprintf("%s%d",random_id,i);
2103 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2108 XBT_INFO("Malformed radical");
2110 res = random_generate(random);
2111 rd_name = bprintf("%s_router",random_id);
2112 rd_value = bprintf("%f",res);
2113 xbt_dict_set(random_value, rd_name, rd_value, free);
2115 xbt_dynar_free(&radical_ends);
2118 xbt_dynar_free(&radical_elements);
2122 static void routing_parse_Erandom(void)
2124 xbt_dict_cursor_t cursor = NULL;
2128 xbt_dict_foreach(random_value, cursor, key, elem) {
2129 XBT_DEBUG("%s = %s",key,elem);
2136 * New methods to init the routing model component from the lua script
2140 * calling parse_S_AS_lua with lua values
2142 void routing_AS_init(const char *AS_id, const char *AS_routing)
2144 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
2148 * calling parse_E_AS_lua to fisnish the creation of routing component
2150 void routing_AS_end(const char *AS_id)
2152 parse_E_AS_lua((char *) AS_id);
2156 * add a host to the network element list
2159 void routing_add_host(const char *host_id)
2161 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2165 * Set a new link on the actual list of link for a route or ASroute
2167 void routing_add_link(const char *link_id)
2169 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2173 *Set the endpoints for a route
2175 void routing_set_route(const char *src_id, const char *dst_id)
2177 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2181 * Store the route by calling parse_E_route_store_route
2183 void routing_store_route(void)
2185 parse_E_route_store_route();