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);
821 xbt_ex_free(exception);
828 * \brief Generic method: find a route between hosts
830 * \param src the source host name
831 * \param dst the destination host name
833 * walk through the routing components tree and find a route between hosts
834 * by calling the differents "get_route" functions in each routing component.
835 * Leaves the caller the responsability to clean the returned dynar.
837 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
839 xbt_dynar_t route = NULL;
840 get_route_latency(src, dst, &route, NULL, 0);
845 static double get_latency(const char *src, const char *dst)
847 double latency = -1.0;
848 get_route_latency(src, dst, NULL, &latency, 0);
853 * \brief Recursive function for finalize
855 * \param rc the source host name
857 * This fuction is call by "finalize". It allow to finalize the
858 * AS or routing components. It delete all the structures.
860 static void _finalize(routing_component_t rc)
863 xbt_dict_cursor_t cursor = NULL;
865 routing_component_t elem;
866 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
869 xbt_dict_t tmp_sons = rc->routing_sons;
870 char *tmp_name = rc->name;
871 xbt_dict_free(&tmp_sons);
873 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
874 current_routing->name);
875 (*(rc->finalize)) (rc);
880 * \brief Generic method: delete all the routing structures
882 * walk through the routing components tree and delete the structures
883 * by calling the differents "finalize" functions in each routing component
885 static void finalize(void)
887 /* delete recursibly all the tree */
888 _finalize(global_routing->root);
889 /* delete last_route */
890 xbt_dynar_free(&(global_routing->last_route));
891 /* delete global routing structure */
892 xbt_free(global_routing);
895 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
897 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
899 //adding my one link routes
902 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
904 xbt_dynar_foreach(onelink_mine, cpt, link) {
905 xbt_dynar_push(ret, &link);
910 xbt_dict_cursor_t cursor = NULL;
911 routing_component_t rc_child;
912 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
913 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
915 xbt_dynar_foreach(onelink_child, cpt, link) {
916 xbt_dynar_push(ret, &link);
923 static xbt_dynar_t get_onelink_routes(void)
925 return recursive_get_onelink_routes(global_routing->root);
928 e_surf_network_element_type_t get_network_element_type(const char
931 network_element_info_t rc = NULL;
933 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
934 if(rc) return rc->rc_type;
936 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
937 if(rc) return rc->rc_type;
939 return SURF_NETWORK_ELEMENT_NULL;
943 * \brief Generic method: create the global routing schema
945 * Make a global routing structure and set all the parsing functions.
947 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
949 /* config the uniq global routing */
950 global_routing = xbt_new0(s_routing_global_t, 1);
951 global_routing->root = NULL;
952 global_routing->get_route = get_route;
953 global_routing->get_route_or_null = get_route_or_null;
954 global_routing->get_latency = get_latency;
955 global_routing->get_route_no_cleanup = get_route_no_cleanup;
956 global_routing->get_onelink_routes = get_onelink_routes;
957 global_routing->get_route_latency = get_route_latency;
958 global_routing->get_network_element_type = get_network_element_type;
959 global_routing->finalize = finalize;
960 global_routing->loopback = loopback;
961 global_routing->size_of_link = size_of_links;
962 global_routing->last_route = NULL;
963 get_link_latency = get_link_latency_fun;
964 /* no current routing at moment */
965 current_routing = NULL;
967 /* parse generic elements */
968 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
969 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
970 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
972 surfxml_add_callback(STag_surfxml_route_cb_list,
973 &parse_S_route_new_and_endpoints_XML);
974 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
975 &parse_S_ASroute_new_and_endpoints);
976 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
977 &parse_S_bypassRoute_new_and_endpoints);
979 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
980 &parse_E_link_ctn_new_elem_XML);
982 surfxml_add_callback(ETag_surfxml_route_cb_list,
983 &parse_E_route_store_route);
984 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
985 &parse_E_ASroute_store_route);
986 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
987 &parse_E_bypassRoute_store_route);
989 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
990 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
992 surfxml_add_callback(STag_surfxml_cluster_cb_list,
993 &routing_parse_Scluster);
995 surfxml_add_callback(STag_surfxml_peer_cb_list,
996 &routing_parse_Speer);
998 surfxml_add_callback(ETag_surfxml_platform_cb_list,
1002 instr_routing_define_callbacks();
1006 void surf_parse_add_callback_config(void)
1008 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1009 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1010 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1011 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
1012 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1015 void surf_parse_models_setup()
1017 routing_parse_Erandom();
1018 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1019 surf_config_models_setup(platform_filename);
1020 free(platform_filename);
1023 /* ************************************************** */
1024 /* ********** PATERN FOR NEW ROUTING **************** */
1026 /* The minimal configuration of a new routing model need the next functions,
1027 * also you need to set at the start of the file, the new model in the model
1028 * list. Remember keep the null ending of the list.
1030 /*** Routing model structure ***/
1032 // s_routing_component_t generic_routing;
1033 // /* things that your routing model need */
1034 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1036 /*** Parse routing model functions ***/
1037 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1038 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1039 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1040 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1041 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1043 /*** Business methods ***/
1044 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1045 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1046 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1048 /*** Creation routing model functions ***/
1049 // static void* model_NEW_create(void) {
1050 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1051 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1052 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1053 // new_component->generic_routing.set_route = model_NEW_set_route;
1054 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1055 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1056 // new_component->generic_routing.get_route = NEW_get_route;
1057 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1058 // new_component->generic_routing.finalize = NEW_finalize;
1059 // /* initialization of internal structures */
1060 // return new_component;
1061 // } /* mandatory */
1062 // static void model_NEW_load(void) {} /* mandatory */
1063 // static void model_NEW_unload(void) {} /* mandatory */
1064 // static void model_NEW_end(void) {} /* mandatory */
1066 /* ************************************************************************** */
1067 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1069 void generic_set_processing_unit(routing_component_t rc,
1072 XBT_DEBUG("Load process unit \"%s\"", name);
1073 int *id = xbt_new0(int, 1);
1074 xbt_dict_t _to_index;
1075 _to_index = current_routing->to_index;
1076 *id = xbt_dict_length(_to_index);
1077 xbt_dict_set(_to_index, name, id, xbt_free);
1080 void generic_set_autonomous_system(routing_component_t rc,
1083 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1084 int *id = xbt_new0(int, 1);
1085 xbt_dict_t _to_index;
1086 _to_index = current_routing->to_index;
1087 *id = xbt_dict_length(_to_index);
1088 xbt_dict_set(_to_index, name, id, xbt_free);
1091 int surf_pointer_resource_cmp(const void *a, const void *b)
1096 int surf_link_resource_cmp(const void *a, const void *b)
1098 return !!memcmp(a,b,global_routing->size_of_link);
1101 void generic_set_bypassroute(routing_component_t rc,
1102 const char *src, const char *dst,
1103 route_extended_t e_route)
1105 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1106 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1109 route_name = bprintf("%s#%s", src, dst);
1110 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1111 "Invalid count of links, must be greater than zero (%s,%s)",
1113 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1114 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1115 src, e_route->src_gateway, dst, e_route->dst_gateway);
1117 route_extended_t new_e_route =
1118 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1119 xbt_dynar_free(&(e_route->generic_route.link_list));
1122 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1123 (void (*)(void *)) generic_free_extended_route);
1124 xbt_free(route_name);
1127 /* ************************************************************************** */
1128 /* *********************** GENERIC BUSINESS METHODS ************************* */
1130 double generic_get_link_latency(routing_component_t rc,
1131 const char *src, const char *dst,
1132 route_extended_t route)
1134 int need_to_clean = route?0:1;
1137 double latency = 0.0;
1139 route = route?route:rc->get_route(rc,src,dst);
1141 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1142 latency += get_link_latency(link);
1144 if(need_to_clean) generic_free_extended_route(route);
1148 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1150 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1153 route_extended_t generic_get_bypassroute(routing_component_t rc,
1157 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1158 routing_component_t src_as, dst_as;
1159 int index_src, index_dst;
1160 xbt_dynar_t path_src = NULL;
1161 xbt_dynar_t path_dst = NULL;
1162 routing_component_t current = NULL;
1163 routing_component_t *current_src = NULL;
1164 routing_component_t *current_dst = NULL;
1166 /* (1) find the as where the src and dst are located */
1167 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1168 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1169 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1170 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1172 if(src_data == NULL || dst_data == NULL)
1173 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1174 src, dst, rc->name);
1176 src_as = ((network_element_info_t)src_data)->rc_component;
1177 dst_as = ((network_element_info_t)dst_data)->rc_component;
1179 /* (2) find the path to the root routing component */
1180 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1182 while (current != NULL) {
1183 xbt_dynar_push(path_src, ¤t);
1184 current = current->routing_father;
1186 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1188 while (current != NULL) {
1189 xbt_dynar_push(path_dst, ¤t);
1190 current = current->routing_father;
1193 /* (3) find the common father */
1194 index_src = path_src->used - 1;
1195 index_dst = path_dst->used - 1;
1196 current_src = xbt_dynar_get_ptr(path_src, index_src);
1197 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1198 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1199 xbt_dynar_pop_ptr(path_src);
1200 xbt_dynar_pop_ptr(path_dst);
1203 current_src = xbt_dynar_get_ptr(path_src, index_src);
1204 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1207 int max_index_src = path_src->used - 1;
1208 int max_index_dst = path_dst->used - 1;
1210 int max_index = max(max_index_src, max_index_dst);
1213 route_extended_t e_route_bypass = NULL;
1215 for (max = 0; max <= max_index; max++) {
1216 for (i = 0; i < max; i++) {
1217 if (i <= max_index_src && max <= max_index_dst) {
1218 char *route_name = bprintf("%s#%s",
1219 (*(routing_component_t *)
1221 (path_src, i)))->name,
1222 (*(routing_component_t *)
1224 (path_dst, max)))->name);
1226 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1227 xbt_free(route_name);
1231 if (max <= max_index_src && i <= max_index_dst) {
1232 char *route_name = bprintf("%s#%s",
1233 (*(routing_component_t *)
1235 (path_src, max)))->name,
1236 (*(routing_component_t *)
1238 (path_dst, i)))->name);
1240 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1241 xbt_free(route_name);
1250 if (max <= max_index_src && max <= max_index_dst) {
1251 char *route_name = bprintf("%s#%s",
1252 (*(routing_component_t *)
1254 (path_src, max)))->name,
1255 (*(routing_component_t *)
1257 (path_dst, max)))->name);
1258 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1259 xbt_free(route_name);
1265 xbt_dynar_free(&path_src);
1266 xbt_dynar_free(&path_dst);
1268 route_extended_t new_e_route = NULL;
1270 if (e_route_bypass) {
1272 unsigned int cpt = 0;
1273 new_e_route = xbt_new0(s_route_extended_t, 1);
1274 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1275 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1276 new_e_route->generic_route.link_list =
1277 xbt_dynar_new(global_routing->size_of_link, NULL);
1278 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1279 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1286 /* ************************************************************************** */
1287 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1290 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1291 void *data, int order)
1297 xbt_dynar_t links = NULL, links_id = NULL;
1299 new_route = xbt_new0(s_route_t, 1);
1300 new_route->link_list =
1301 xbt_dynar_new(global_routing->size_of_link, NULL);
1303 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1304 "the hierarchy type is not SURF_ROUTING_BASE");
1306 links = ((route_t) data)->link_list;
1309 links_id = new_route->link_list;
1311 xbt_dynar_foreach(links, cpt, link_name) {
1314 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1317 xbt_dynar_push(links_id, &link);
1319 xbt_dynar_unshift(links_id, &link);
1321 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1328 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1329 void *data, int order)
1333 route_extended_t e_route, new_e_route;
1336 xbt_dynar_t links = NULL, links_id = NULL;
1338 new_e_route = xbt_new0(s_route_extended_t, 1);
1339 new_e_route->generic_route.link_list =
1340 xbt_dynar_new(global_routing->size_of_link, NULL);
1341 new_e_route->src_gateway = NULL;
1342 new_e_route->dst_gateway = NULL;
1344 xbt_assert(hierarchy == SURF_ROUTING_BASE
1345 || hierarchy == SURF_ROUTING_RECURSIVE,
1346 "the hierarchy type is not defined");
1348 if (hierarchy == SURF_ROUTING_BASE) {
1350 route = (route_t) data;
1351 links = route->link_list;
1353 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1355 e_route = (route_extended_t) data;
1356 xbt_assert(e_route->src_gateway
1357 && e_route->dst_gateway, "bad gateway, is null");
1358 links = e_route->generic_route.link_list;
1360 /* remeber not erase the gateway names */
1361 new_e_route->src_gateway = strdup(e_route->src_gateway);
1362 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1365 links_id = new_e_route->generic_route.link_list;
1367 xbt_dynar_foreach(links, cpt, link_name) {
1370 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1373 xbt_dynar_push(links_id, &link);
1375 xbt_dynar_unshift(links_id, &link);
1377 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1383 void generic_free_route(route_t route)
1386 xbt_dynar_free(&(route->link_list));
1391 void generic_free_extended_route(route_extended_t e_route)
1394 xbt_dynar_free(&(e_route->generic_route.link_list));
1395 if (e_route->src_gateway)
1396 xbt_free(e_route->src_gateway);
1397 if (e_route->dst_gateway)
1398 xbt_free(e_route->dst_gateway);
1403 static routing_component_t generic_as_exist(routing_component_t find_from,
1404 routing_component_t to_find)
1406 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1407 xbt_dict_cursor_t cursor = NULL;
1410 routing_component_t elem;
1411 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1412 if (to_find == elem || generic_as_exist(elem, to_find)) {
1423 generic_autonomous_system_exist(routing_component_t rc, char *element)
1425 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1426 routing_component_t element_as, result, elem;
1427 xbt_dict_cursor_t cursor = NULL;
1429 element_as = ((network_element_info_t)
1430 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1431 result = ((routing_component_t) - 1);
1432 if (element_as != rc)
1433 result = generic_as_exist(rc, element_as);
1437 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1438 found = !strcmp(elem->name, element);
1449 generic_processing_units_exist(routing_component_t rc, char *element)
1451 routing_component_t element_as;
1452 element_as = ((network_element_info_t)
1453 xbt_lib_get_or_null(host_lib,
1454 element, ROUTING_HOST_LEVEL))->rc_component;
1455 if (element_as == rc)
1457 return generic_as_exist(rc, element_as);
1460 void generic_src_dst_check(routing_component_t rc, const char *src,
1464 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1465 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1466 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1467 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1469 if(src_data == NULL || dst_data == NULL)
1470 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1471 src, dst, rc->name);
1473 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1474 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1476 if(src_as != dst_as)
1477 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1478 src, src_as->name, dst, dst_as->name);
1480 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1481 src,dst,src_as->name, dst_as->name,rc->name);
1484 static void routing_parse_Sconfig(void)
1486 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1489 static void routing_parse_Econfig(void)
1491 xbt_dict_cursor_t cursor = NULL;
1495 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1496 cfg = bprintf("%s:%s",key,elem);
1497 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1498 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1500 XBT_INFO("The custom configuration '%s' is already define by user!",key);
1503 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1506 void routing_parse_Scluster(void)
1508 static int AX_ptr = 0;
1510 char *cluster_id = A_surfxml_cluster_id;
1511 char *cluster_prefix = A_surfxml_cluster_prefix;
1512 char *cluster_suffix = A_surfxml_cluster_suffix;
1513 char *cluster_radical = A_surfxml_cluster_radical;
1514 char *cluster_core = A_surfxml_cluster_core;
1515 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1516 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1517 char *cluster_power = xbt_strdup(A_surfxml_cluster_power);
1518 char *cluster_bw = xbt_strdup(A_surfxml_cluster_bw);
1519 char *cluster_lat = xbt_strdup(A_surfxml_cluster_lat);
1520 char *host_id, *groups, *link_id = NULL;
1521 char *router_id = xbt_strdup(A_surfxml_cluster_router_id);
1522 char *availability_file = xbt_strdup(A_surfxml_cluster_availability_file);
1523 char *state_file = xbt_strdup(A_surfxml_cluster_state_file);
1525 if(xbt_dict_size(patterns)==0)
1526 patterns = xbt_dict_new();
1528 xbt_dict_set(patterns,"id",cluster_id,NULL);
1529 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
1530 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
1532 cluster_power = replace_random_parameter(cluster_power);
1533 cluster_bw = replace_random_parameter(cluster_bw);
1534 cluster_lat = replace_random_parameter(cluster_lat);
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, xbt_dynar_get_as(radical_ends, 0, char *));
1562 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
1563 link_id = bprintf("%s_link_%d", cluster_id, start);
1564 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1565 A_surfxml_host_state = A_surfxml_host_state_ON;
1567 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, cluster_power);
1568 SURFXML_BUFFER_SET(host_id, host_id);
1569 SURFXML_BUFFER_SET(host_power, cluster_power);
1571 if(!strcmp(A_surfxml_cluster_availability_file,"")){
1572 char* tmp_availability_file = xbt_strdup(availability_file);
1573 xbt_str_varsubst(tmp_availability_file,patterns);
1574 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1575 SURFXML_BUFFER_SET(host_availability_file, tmp_availability_file);
1576 xbt_free(tmp_availability_file);
1580 XBT_DEBUG("\tavailability_file=\"\"");
1581 SURFXML_BUFFER_SET(host_availability_file, "");
1583 if(!strcmp(A_surfxml_cluster_state_file,"")){
1584 char *tmp_state_file = xbt_strdup(state_file);
1585 xbt_str_varsubst(tmp_state_file,patterns);
1586 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1587 SURFXML_BUFFER_SET(host_state_file, tmp_state_file);
1588 xbt_free(tmp_state_file);
1592 XBT_DEBUG("\tstate_file=\"\"");
1593 SURFXML_BUFFER_SET(host_state_file, "");
1596 SURFXML_BUFFER_SET(host_core, cluster_core);
1597 SURFXML_BUFFER_SET(host_availability, "1.0");
1598 SURFXML_BUFFER_SET(host_coordinates, "");
1599 SURFXML_START_TAG(host);
1600 SURFXML_END_TAG(host);
1601 XBT_DEBUG("</host>");
1603 A_surfxml_link_state = A_surfxml_link_state_ON;
1604 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1605 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1606 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1607 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1608 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1610 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
1612 SURFXML_BUFFER_SET(link_id, link_id);
1613 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
1614 SURFXML_BUFFER_SET(link_latency, cluster_lat);
1615 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1616 SURFXML_BUFFER_SET(link_latency_file, "");
1617 SURFXML_BUFFER_SET(link_state_file, "");
1618 SURFXML_START_TAG(link);
1619 SURFXML_END_TAG(link);
1627 surf_parse_get_int(&start,
1628 xbt_dynar_get_as(radical_ends, 0, char *));
1629 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1630 for (i = start; i <= end; i++) {
1631 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
1632 link_id = bprintf("%s_link_%d", cluster_id, i);
1633 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1634 A_surfxml_host_state = A_surfxml_host_state_ON;
1636 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, cluster_power);
1637 SURFXML_BUFFER_SET(host_id, host_id);
1638 SURFXML_BUFFER_SET(host_power, cluster_power);
1640 if(!strcmp(A_surfxml_cluster_availability_file,"")){
1641 char* tmp_availability_file = xbt_strdup(availability_file);
1642 xbt_str_varsubst(tmp_availability_file,patterns);
1643 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1644 SURFXML_BUFFER_SET(host_availability_file, tmp_availability_file);
1645 xbt_free(tmp_availability_file);
1649 XBT_DEBUG("\tavailability_file=\"\"");
1650 SURFXML_BUFFER_SET(host_availability_file, "");
1652 if(!strcmp(A_surfxml_cluster_state_file,"")){
1653 char *tmp_state_file = xbt_strdup(state_file);
1654 xbt_str_varsubst(tmp_state_file,patterns);
1655 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1656 SURFXML_BUFFER_SET(host_state_file, tmp_state_file);
1657 xbt_free(tmp_state_file);
1661 XBT_DEBUG("\tstate_file=\"\"");
1662 SURFXML_BUFFER_SET(host_state_file, "");
1665 SURFXML_BUFFER_SET(host_core, cluster_core);
1666 SURFXML_BUFFER_SET(host_availability, "1.0");
1667 SURFXML_BUFFER_SET(host_coordinates, "");
1668 SURFXML_START_TAG(host);
1669 SURFXML_END_TAG(host);
1670 XBT_DEBUG("</host>");
1672 A_surfxml_link_state = A_surfxml_link_state_ON;
1673 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1674 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1675 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1676 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1677 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1679 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
1681 SURFXML_BUFFER_SET(link_id, link_id);
1682 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
1683 SURFXML_BUFFER_SET(link_latency, cluster_lat);
1684 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1685 SURFXML_BUFFER_SET(link_latency_file, "");
1686 SURFXML_BUFFER_SET(link_state_file, "");
1687 SURFXML_START_TAG(link);
1688 SURFXML_END_TAG(link);
1696 XBT_DEBUG("Malformed radical");
1700 xbt_dynar_free(&radical_ends);
1702 xbt_dynar_free(&radical_elements);
1705 if(!strcmp(router_id,""))
1706 router_id = bprintf("%s%s_router%s", cluster_prefix, cluster_id, cluster_suffix);
1708 XBT_DEBUG("<router id=\"%s\"/>", router_id);
1709 SURFXML_BUFFER_SET(router_id, router_id);
1710 SURFXML_BUFFER_SET(router_coordinates, "");
1711 SURFXML_START_TAG(router);
1712 SURFXML_END_TAG(router);
1714 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1715 char *link_backbone = bprintf("%s_backbone", cluster_id);
1716 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
1717 A_surfxml_link_state = A_surfxml_link_state_ON;
1718 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1719 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1720 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1721 SURFXML_BUFFER_SET(link_id, link_backbone);
1722 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
1723 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
1724 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1725 SURFXML_BUFFER_SET(link_latency_file, "");
1726 SURFXML_BUFFER_SET(link_state_file, "");
1727 SURFXML_START_TAG(link);
1728 SURFXML_END_TAG(link);
1729 free(link_backbone);
1734 char *new_suffix = xbt_strdup("");
1736 radical_elements = xbt_str_split(cluster_suffix, ".");
1737 xbt_dynar_foreach(radical_elements, iter, groups) {
1738 if (strcmp(groups, "")) {
1739 char *old_suffix = new_suffix;
1740 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1744 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
1745 xbt_dynar_free(&radical_elements);
1746 xbt_free(new_suffix);
1748 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
1749 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
1750 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
1752 //from router to router
1753 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, router_id);
1754 XBT_DEBUG("symmetrical=\"NO\">");
1755 SURFXML_BUFFER_SET(route_src, router_id);
1756 SURFXML_BUFFER_SET(route_dst, router_id);
1757 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1758 SURFXML_START_TAG(route);
1760 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1761 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1762 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1763 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1764 SURFXML_START_TAG(link_ctn);
1765 SURFXML_END_TAG(link_ctn);
1768 XBT_DEBUG("</route>");
1769 SURFXML_END_TAG(route);
1771 //from host to router
1772 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, router_id);
1773 XBT_DEBUG("symmetrical=\"NO\">");
1774 SURFXML_BUFFER_SET(route_src, route_src_dst);
1775 SURFXML_BUFFER_SET(route_dst, router_id);
1776 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1777 SURFXML_START_TAG(route);
1779 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1780 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1781 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1782 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1783 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1784 SURFXML_START_TAG(link_ctn);
1785 SURFXML_END_TAG(link_ctn);
1787 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1788 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1789 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1790 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1791 SURFXML_START_TAG(link_ctn);
1792 SURFXML_END_TAG(link_ctn);
1795 XBT_DEBUG("</route>");
1796 SURFXML_END_TAG(route);
1798 //from router to host
1799 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, route_src_dst);
1800 XBT_DEBUG("symmetrical=\"NO\">");
1801 SURFXML_BUFFER_SET(route_src, router_id);
1802 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1803 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1804 SURFXML_START_TAG(route);
1806 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1807 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1808 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1809 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1810 SURFXML_START_TAG(link_ctn);
1811 SURFXML_END_TAG(link_ctn);
1814 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1815 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1816 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1817 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1818 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1819 SURFXML_START_TAG(link_ctn);
1820 SURFXML_END_TAG(link_ctn);
1822 XBT_DEBUG("</route>");
1823 SURFXML_END_TAG(route);
1826 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
1827 XBT_DEBUG("symmetrical=\"NO\">");
1828 SURFXML_BUFFER_SET(route_src, route_src_dst);
1829 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1830 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1831 SURFXML_START_TAG(route);
1833 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1834 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1835 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1836 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1837 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1838 SURFXML_START_TAG(link_ctn);
1839 SURFXML_END_TAG(link_ctn);
1841 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1842 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1843 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1844 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1845 SURFXML_START_TAG(link_ctn);
1846 SURFXML_END_TAG(link_ctn);
1849 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1850 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1851 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1852 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1853 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1854 SURFXML_START_TAG(link_ctn);
1855 SURFXML_END_TAG(link_ctn);
1857 XBT_DEBUG("</route>");
1858 SURFXML_END_TAG(route);
1860 free(pcre_link_dst);
1861 free(pcre_link_backbone);
1862 free(pcre_link_src);
1863 free(route_src_dst);
1865 xbt_free(cluster_bw);
1866 xbt_free(cluster_lat);
1867 xbt_free(cluster_power);
1868 xbt_free(availability_file);
1869 xbt_free(state_file);
1871 xbt_free(router_id);
1872 xbt_dict_free(&patterns);
1875 SURFXML_END_TAG(AS);
1878 surfxml_bufferstack_pop(1);
1881 * This function take a string and replace parameters from patterns dict.
1882 * It returns the new value.
1884 static char* replace_random_parameter(char * string)
1886 char *test_string = NULL;
1888 if(xbt_dict_size(random_value)==0)
1891 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1892 test_string = bprintf("${%s}", string);
1893 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1895 if (strcmp(test_string,"")) { //if not empty, keep this value.
1897 string = test_string;
1898 } //In other case take old value (without ${})
1904 static void clean_dict_random(void)
1906 xbt_dict_free(&random_value);
1907 xbt_dict_free(&patterns);
1910 static void routing_parse_Speer(void)
1912 static int AX_ptr = 0;
1914 char *peer_id = A_surfxml_peer_id;
1915 char *peer_power = A_surfxml_peer_power;
1916 char *peer_bw_in = A_surfxml_peer_bw_in;
1917 char *peer_bw_out = A_surfxml_peer_bw_out;
1918 char *peer_lat = A_surfxml_peer_lat;
1919 char *peer_coord = A_surfxml_peer_coordinates;
1920 char *peer_state_file = A_surfxml_peer_state_file;
1921 char *peer_availability_file = A_surfxml_peer_availability_file;
1923 char *host_id = NULL;
1924 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1926 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1927 static unsigned int surfxml_buffer_stack_stack[1024];
1929 surfxml_buffer_stack_stack[0] = 0;
1931 surfxml_bufferstack_push(1);
1933 SURFXML_BUFFER_SET(AS_id, peer_id);
1935 SURFXML_BUFFER_SET(AS_routing, "Full");
1936 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
1938 SURFXML_START_TAG(AS);
1941 host_id = bprintf("peer_%s", peer_id);
1942 router_id = bprintf("router_%s", peer_id);
1943 link_id_up = bprintf("link_%s_up", peer_id);
1944 link_id_down = bprintf("link_%s_down", peer_id);
1946 link_router = bprintf("%s_link_router", peer_id);
1947 link_backbone = bprintf("%s_backbone", peer_id);
1949 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
1950 A_surfxml_host_state = A_surfxml_host_state_ON;
1951 SURFXML_BUFFER_SET(host_id, host_id);
1952 SURFXML_BUFFER_SET(host_power, peer_power);
1953 SURFXML_BUFFER_SET(host_availability, "1.0");
1954 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
1955 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
1956 SURFXML_BUFFER_SET(host_coordinates, "");
1957 SURFXML_BUFFER_SET(host_core, "1.0");
1958 SURFXML_START_TAG(host);
1959 SURFXML_END_TAG(host);
1961 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
1962 SURFXML_BUFFER_SET(router_id, router_id);
1963 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
1964 SURFXML_START_TAG(router);
1965 SURFXML_END_TAG(router);
1967 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
1968 A_surfxml_link_state = A_surfxml_link_state_ON;
1969 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1970 SURFXML_BUFFER_SET(link_id, link_id_up);
1971 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
1972 SURFXML_BUFFER_SET(link_latency, peer_lat);
1973 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1974 SURFXML_BUFFER_SET(link_latency_file, "");
1975 SURFXML_BUFFER_SET(link_state_file, "");
1976 SURFXML_START_TAG(link);
1977 SURFXML_END_TAG(link);
1979 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
1980 A_surfxml_link_state = A_surfxml_link_state_ON;
1981 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1982 SURFXML_BUFFER_SET(link_id, link_id_down);
1983 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
1984 SURFXML_BUFFER_SET(link_latency, peer_lat);
1985 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1986 SURFXML_BUFFER_SET(link_latency_file, "");
1987 SURFXML_BUFFER_SET(link_state_file, "");
1988 SURFXML_START_TAG(link);
1989 SURFXML_END_TAG(link);
1994 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1995 XBT_DEBUG("symmetrical=\"NO\">");
1996 SURFXML_BUFFER_SET(route_src, host_id);
1997 SURFXML_BUFFER_SET(route_dst, router_id);
1998 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1999 SURFXML_START_TAG(route);
2001 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
2002 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
2003 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2004 SURFXML_START_TAG(link_ctn);
2005 SURFXML_END_TAG(link_ctn);
2007 XBT_DEBUG("</route>");
2008 SURFXML_END_TAG(route);
2011 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
2012 XBT_DEBUG("symmetrical=\"NO\">");
2013 SURFXML_BUFFER_SET(route_src, router_id);
2014 SURFXML_BUFFER_SET(route_dst, host_id);
2015 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2016 SURFXML_START_TAG(route);
2018 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
2019 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
2020 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2021 SURFXML_START_TAG(link_ctn);
2022 SURFXML_END_TAG(link_ctn);
2024 XBT_DEBUG("</route>");
2025 SURFXML_END_TAG(route);
2028 SURFXML_END_TAG(AS);
2031 //xbt_dynar_free(&tab_elements_num);
2035 free(link_backbone);
2038 surfxml_bufferstack_pop(1);
2041 static void routing_parse_Srandom(void)
2043 double mean, std, min, max, seed;
2044 char *random_id = A_surfxml_random_id;
2045 char *random_radical = A_surfxml_random_radical;
2046 char *rd_name = NULL;
2048 surf_parse_get_double(&mean,A_surfxml_random_mean);
2049 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2050 surf_parse_get_double(&min,A_surfxml_random_min);
2051 surf_parse_get_double(&max,A_surfxml_random_max);
2052 surf_parse_get_double(&seed,A_surfxml_random_seed);
2056 random_data_t random = xbt_new0(s_random_data_t, 1);
2059 xbt_dynar_t radical_elements;
2063 xbt_dynar_t radical_ends;
2065 random->generator = A_surfxml_random_generator;
2066 random->seed = seed;
2070 /* Check user stupidities */
2072 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2074 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2077 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2080 /* normalize the mean and standard deviation before storing */
2081 random->mean = (mean - min) / (max - min);
2082 random->std = std / (max - min);
2084 if (random->mean * (1 - random->mean) < random->std * random->std)
2085 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2086 random->mean, random->std);
2088 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2098 if(xbt_dict_size(random_value)==0)
2099 random_value = xbt_dict_new();
2101 if(!strcmp(random_radical,""))
2103 res = random_generate(random);
2104 rd_value = bprintf("%f",res);
2105 xbt_dict_set(random_value, random_id, rd_value, free);
2109 radical_elements = xbt_str_split(random_radical, ",");
2110 xbt_dynar_foreach(radical_elements, iter, groups) {
2111 radical_ends = xbt_str_split(groups, "-");
2112 switch (xbt_dynar_length(radical_ends)) {
2114 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2115 res = random_generate(random);
2116 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2117 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2121 case 2: surf_parse_get_int(&start,
2122 xbt_dynar_get_as(radical_ends, 0, char *));
2123 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2124 for (i = start; i <= end; i++) {
2125 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2126 res = random_generate(random);
2127 tmpbuf = bprintf("%s%d",random_id,i);
2128 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2133 XBT_INFO("Malformed radical");
2136 res = random_generate(random);
2137 rd_name = bprintf("%s_router",random_id);
2138 rd_value = bprintf("%f",res);
2139 xbt_dict_set(random_value, rd_name, rd_value, free);
2141 xbt_dynar_free(&radical_ends);
2144 xbt_dynar_free(&radical_elements);
2148 static void routing_parse_Erandom(void)
2150 xbt_dict_cursor_t cursor = NULL;
2154 xbt_dict_foreach(random_value, cursor, key, elem) {
2155 XBT_DEBUG("%s = %s",key,elem);
2162 * New methods to init the routing model component from the lua script
2166 * calling parse_S_AS_lua with lua values
2168 void routing_AS_init(const char *AS_id, const char *AS_routing)
2170 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
2174 * calling parse_E_AS_lua to fisnish the creation of routing component
2176 void routing_AS_end(const char *AS_id)
2178 parse_E_AS_lua((char *) AS_id);
2182 * add a host to the network element list
2185 void routing_add_host(const char *host_id)
2187 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2191 * Set a new link on the actual list of link for a route or ASroute
2193 void routing_add_link(const char *link_id)
2195 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2199 *Set the endpoints for a route
2201 void routing_set_route(const char *src_id, const char *dst_id)
2203 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2207 * Store the route by calling parse_E_route_store_route
2209 void routing_store_route(void)
2211 parse_E_route_store_route();