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. */
8 #include <pcre.h> /* regular expression library */
10 #include "surf_routing_private.h"
11 #include "surf/surf_routing.h"
14 int ROUTING_HOST_LEVEL; //Routing level
15 int SURF_CPU_LEVEL; //Surf cpu level
16 int SURF_WKS_LEVEL; //Surf workstation level
17 int SIMIX_HOST_LEVEL; //Simix level
18 int MSG_HOST_LEVEL; //Msg level
19 int SD_HOST_LEVEL; //Simdag level
20 int COORD_HOST_LEVEL; //Coordinates level
21 int NS3_HOST_LEVEL; //host node for ns3
24 int SD_LINK_LEVEL; //Simdag level
25 int SURF_LINK_LEVEL; //Surf level
26 int NS3_LINK_LEVEL; //link for ns3
28 xbt_lib_t as_router_lib;
29 int ROUTING_ASR_LEVEL; //Routing level
30 int COORD_ASR_LEVEL; //Coordinates level
31 int NS3_ASR_LEVEL; //host node for ns3
33 static xbt_dict_t patterns = NULL;
34 static xbt_dict_t random_value = NULL;
37 routing_global_t global_routing = NULL;
38 routing_component_t current_routing = NULL;
39 model_type_t current_routing_model = NULL;
41 /* global parse functions */
42 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
43 static const char *src = NULL; /* temporary store the source name of a route */
44 static const char *dst = NULL; /* temporary store the destination name of a route */
45 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
46 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
47 static double_f_cpvoid_t get_link_latency = NULL;
49 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
51 static void routing_parse_Speer(void); /* peer bypass */
52 static void routing_parse_Srandom(void); /* random bypass */
53 static void routing_parse_Erandom(void); /* random bypass */
55 static void routing_parse_Sconfig(void); /* config Tag */
56 static void routing_parse_Econfig(void); /* config Tag */
58 static char* replace_random_parameter(char * chaine);
59 static void clean_dict_random(void);
61 /* this lines are only for replace use like index in the model table */
66 SURF_MODEL_DIJKSTRACACHE,
73 struct s_model_type routing_models[] = { {"Full",
74 "Full routing data (fast, large memory requirements, fully expressive)",
80 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
81 model_floyd_create, model_floyd_load, model_floyd_unload,
84 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
85 model_dijkstra_create, model_dijkstra_both_load,
86 model_dijkstra_both_unload, model_dijkstra_both_end},
88 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
89 model_dijkstracache_create, model_dijkstra_both_load,
90 model_dijkstra_both_unload, model_dijkstra_both_end},
91 {"none", "No routing (usable with Constant network only)",
92 model_none_create, model_none_load, model_none_unload, model_none_end},
94 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
95 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
96 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
97 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
99 {NULL, NULL, NULL, NULL, NULL, NULL}
102 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
104 double src_coord, dst_coord;
106 src_coord = atof(xbt_dynar_get_as(src, index, char *));
107 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
109 return (src_coord-dst_coord)*(src_coord-dst_coord);
113 static double base_vivaldi_get_latency (const char *src, const char *dst)
115 double euclidean_dist;
116 xbt_dynar_t src_ctn, dst_ctn;
117 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
118 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
119 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
120 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
122 if(dst_ctn == NULL || src_ctn == NULL)
123 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
125 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
126 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
128 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
131 return euclidean_dist / 1000;
134 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
136 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
137 int need_to_clean = e_route?0:1;
139 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
140 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
141 if(need_to_clean) generic_free_extended_route(e_route);
144 return base_vivaldi_get_latency(src,dst);
149 * \brief Add a "host" to the network element list
151 static void parse_S_host(const char *host_id, const char* coord)
153 network_element_info_t info = NULL;
154 if (current_routing->hierarchy == SURF_ROUTING_NULL)
155 current_routing->hierarchy = SURF_ROUTING_BASE;
156 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
157 "Reading a host, processing unit \"%s\" already exists",
159 xbt_assert(current_routing->set_processing_unit,
160 "no defined method \"set_processing_unit\" in \"%s\"",
161 current_routing->name);
162 (*(current_routing->set_processing_unit)) (current_routing, host_id);
163 info = xbt_new0(s_network_element_info_t, 1);
164 info->rc_component = current_routing;
165 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
166 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
167 if (strcmp(coord,"")) {
168 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
169 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
170 xbt_dynar_shrink(ctn, 0);
171 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
175 static void parse_E_host(void)
177 xbt_dict_cursor_t cursor = NULL;
181 xbt_dict_foreach(current_property_set, cursor, key, elem) {
182 XBT_DEBUG("property : %s = %s",key,elem);
187 * \brief Add a host to the network element list from XML
189 static void parse_S_host_XML(void)
191 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
193 static void parse_E_host_XML(void)
199 * \brief Add a host to the network element list from lua script
201 static void parse_S_host_lua(const char *host_id, const char *coord)
203 parse_S_host(host_id, coord);
208 * \brief Add a "router" to the network element list
210 static void parse_S_router(const char *router_id)
212 network_element_info_t info = NULL;
214 if (current_routing->hierarchy == SURF_ROUTING_NULL)
215 current_routing->hierarchy = SURF_ROUTING_BASE;
216 xbt_assert(!xbt_lib_get_or_null(as_router_lib,A_surfxml_router_id, ROUTING_ASR_LEVEL),
217 "Reading a router, processing unit \"%s\" already exists",
219 xbt_assert(current_routing->set_processing_unit,
220 "no defined method \"set_processing_unit\" in \"%s\"",
221 current_routing->name);
222 (*(current_routing->set_processing_unit)) (current_routing,
224 info = xbt_new0(s_network_element_info_t, 1);
225 info->rc_component = current_routing;
226 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
228 xbt_lib_set(as_router_lib,router_id,ROUTING_ASR_LEVEL,(void *) info);
229 if (strcmp(A_surfxml_router_coordinates,"")) {
230 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
231 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
232 xbt_dynar_shrink(ctn, 0);
233 xbt_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn);
238 * brief Add a "router" to the network element list from XML description
240 static void parse_S_router_XML(void)
242 return parse_S_router(A_surfxml_router_id);
246 * brief Add a "router" to the network element list from XML description
248 static void parse_S_router_lua(const char* router_id)
250 return parse_S_router(router_id);
254 * \brief Set the endponints for a route
256 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
258 if (src != NULL && dst != NULL && link_list != NULL)
259 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
263 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
264 "Some limits are null in the route between \"%s\" and \"%s\"",
266 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
270 * \brief Set the endpoints for a route from XML
272 static void parse_S_route_new_and_endpoints_XML(void)
274 parse_S_route_new_and_endpoints(A_surfxml_route_src,
275 A_surfxml_route_dst);
279 * \brief Set the endpoints for a route from lua
281 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
283 parse_S_route_new_and_endpoints(id_src, id_dst);
287 * \brief Set the endponints and gateways for a ASroute
289 static void parse_S_ASroute_new_and_endpoints(void)
291 if (src != NULL && dst != NULL && link_list != NULL)
292 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
293 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
294 src = A_surfxml_ASroute_src;
295 dst = A_surfxml_ASroute_dst;
296 gw_src = A_surfxml_ASroute_gw_src;
297 gw_dst = A_surfxml_ASroute_gw_dst;
298 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
299 || strlen(gw_dst) > 0,
300 "Some limits are null in the route between \"%s\" and \"%s\"",
302 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
306 * \brief Set the endponints for a bypassRoute
308 static void parse_S_bypassRoute_new_and_endpoints(void)
310 if (src != NULL && dst != NULL && link_list != NULL)
312 "Bypass Route between %s to %s can not be defined",
313 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
314 src = A_surfxml_bypassRoute_src;
315 dst = A_surfxml_bypassRoute_dst;
316 gw_src = A_surfxml_bypassRoute_gw_src;
317 gw_dst = A_surfxml_bypassRoute_gw_dst;
318 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
319 || strlen(gw_dst) > 0,
320 "Some limits are null in the route between \"%s\" and \"%s\"",
322 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
326 * \brief Set a new link on the actual list of link for a route or ASroute
328 static void parse_E_link_ctn_new_elem(const char *link_id)
331 val = xbt_strdup(link_id);
332 xbt_dynar_push(link_list, &val);
336 * \brief Set a new link on the actual list of link for a route or ASroute from XML
339 static void parse_E_link_ctn_new_elem_XML(void)
341 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
342 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
343 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
344 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
345 parse_E_link_ctn_new_elem(link_id);
348 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
349 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
350 parse_E_link_ctn_new_elem(link_id);
356 * \brief Set a new link on the actual list of link for a route or ASroute from lua
358 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
360 parse_E_link_ctn_new_elem(link_id);
364 * \brief Store the route by calling the set_route function of the current routing component
366 static void parse_E_route_store_route(void)
368 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
369 route->generic_route.link_list = link_list;
370 xbt_assert(current_routing->set_route,
371 "no defined method \"set_route\" in \"%s\"",
372 current_routing->name);
373 (*(current_routing->set_route)) (current_routing, src, dst, route);
380 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
382 static void parse_E_ASroute_store_route(void)
384 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
385 e_route->generic_route.link_list = link_list;
386 e_route->src_gateway = xbt_strdup(gw_src);
387 e_route->dst_gateway = xbt_strdup(gw_dst);
388 xbt_assert(current_routing->set_ASroute,
389 "no defined method \"set_ASroute\" in \"%s\"",
390 current_routing->name);
391 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
400 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
402 static void parse_E_bypassRoute_store_route(void)
404 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
405 e_route->generic_route.link_list = link_list;
406 e_route->src_gateway = xbt_strdup(gw_src);
407 e_route->dst_gateway = xbt_strdup(gw_dst);
408 xbt_assert(current_routing->set_bypassroute,
409 "no defined method \"set_bypassroute\" in \"%s\"",
410 current_routing->name);
411 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
421 * \brief Make a new routing component
423 * make the new structure and
424 * set the parsing functions to allows parsing the part of the routing tree
426 static void parse_S_AS(char *AS_id, char *AS_routing)
428 routing_component_t new_routing;
429 model_type_t model = NULL;
430 char *wanted = AS_routing;
432 /* seach the routing model */
433 for (cpt = 0; routing_models[cpt].name; cpt++)
434 if (!strcmp(wanted, routing_models[cpt].name))
435 model = &routing_models[cpt];
436 /* if its not exist, error */
438 fprintf(stderr, "Routing model %s not found. Existing models:\n",
440 for (cpt = 0; routing_models[cpt].name; cpt++)
441 if (!strcmp(wanted, routing_models[cpt].name))
442 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
443 routing_models[cpt].desc);
447 /* make a new routing component */
448 new_routing = (routing_component_t) (*(model->create)) ();
449 new_routing->routing = model;
450 new_routing->hierarchy = SURF_ROUTING_NULL;
451 new_routing->name = xbt_strdup(AS_id);
452 new_routing->routing_sons = xbt_dict_new();
454 /* Hack for Vivaldi */
455 if(!strcmp(model->name,"Vivaldi"))
456 new_routing->get_latency = vivaldi_get_link_latency;
458 if (current_routing == NULL && global_routing->root == NULL) {
460 /* it is the first one */
461 new_routing->routing_father = NULL;
462 global_routing->root = new_routing;
464 } else if (current_routing != NULL && global_routing->root != NULL) {
466 xbt_assert(!xbt_dict_get_or_null
467 (current_routing->routing_sons, AS_id),
468 "The AS \"%s\" already exists", AS_id);
469 /* it is a part of the tree */
470 new_routing->routing_father = current_routing;
471 /* set the father behavior */
472 if (current_routing->hierarchy == SURF_ROUTING_NULL)
473 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
474 /* add to the sons dictionary */
475 xbt_dict_set(current_routing->routing_sons, AS_id,
476 (void *) new_routing, NULL);
477 /* add to the father element list */
478 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
479 /* unload the prev parse rules */
480 (*(current_routing->routing->unload)) ();
483 THROWF(arg_error, 0, "All defined components must be belong to a AS");
485 /* set the new parse rules */
486 (*(new_routing->routing->load)) ();
487 /* set the new current component of the tree */
488 current_routing = new_routing;
492 * Detect the routing model type of the routing component from XML platforms
494 static void parse_S_AS_XML(void)
496 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
500 * define the routing model type of routing component from lua script
502 static void parse_S_AS_lua(char *id, char *mode)
504 parse_S_AS(id, mode);
509 * \brief Finish the creation of a new routing component
511 * When you finish to read the routing component, other structures must be created.
512 * the "end" method allow to do that for any routing model type
514 static void parse_E_AS(const char *AS_id)
517 if (current_routing == NULL) {
518 THROWF(arg_error, 0, "Close AS(%s), that never open", AS_id);
520 network_element_info_t info = NULL;
521 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
522 "The AS \"%s\" already exists",current_routing->name);
523 info = xbt_new0(s_network_element_info_t, 1);
524 info->rc_component = current_routing->routing_father;
525 info->rc_type = SURF_NETWORK_ELEMENT_AS;
526 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
528 (*(current_routing->routing->unload)) ();
529 (*(current_routing->routing->end)) ();
530 current_routing = current_routing->routing_father;
531 if (current_routing != NULL)
532 (*(current_routing->routing->load)) ();
537 * \brief Finish the creation of a new routing component from XML
539 static void parse_E_AS_XML(void)
541 parse_E_AS(A_surfxml_AS_id);
545 * \brief Finish the creation of a new routing component from lua
547 static void parse_E_AS_lua(const char *id)
552 /* Aux Business methods */
555 * \brief Get the AS name of the element
557 * \param name the host name
560 static char* elements_As_name(const char *name)
562 routing_component_t as_comp;
564 /* (1) find the as where the host is located */
565 as_comp = ((network_element_info_t)
566 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
567 return as_comp->name;
572 * \brief Get the AS father and the first elements of the chain
574 * \param src the source host name
575 * \param dst the destination host name
577 * Get the common father of the to processing units, and the first different
578 * father in the chain
580 static void elements_father(const char *src, const char *dst,
581 routing_component_t *res_father,
582 routing_component_t *res_src,
583 routing_component_t *res_dst)
585 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
586 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
587 routing_component_t src_as, dst_as;
588 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
589 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
592 routing_component_t current;
593 routing_component_t current_src;
594 routing_component_t current_dst;
595 routing_component_t father;
597 /* (1) find the as where the src and dst are located */
598 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
600 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
603 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
605 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
606 src_as = src_data->rc_component;
607 dst_as = dst_data->rc_component;
609 xbt_assert(src_as && dst_as,
610 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
612 /* (2) find the path to the root routing component */
613 for (current = src_as ; current != NULL ; current = current->routing_father) {
614 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
615 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
616 path_src[index_src++] = current;
618 for (current = dst_as ; current != NULL ; current = current->routing_father) {
619 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
620 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
621 path_dst[index_dst++] = current;
624 /* (3) find the common father */
626 current_src = path_src[--index_src];
627 current_dst = path_dst[--index_dst];
628 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
630 /* (4) they are not in the same routing component, make the path */
631 if (current_src == current_dst)
632 father = current_src;
634 father = path_src[index_src + 1];
636 /* (5) result generation */
637 *res_father = father; /* first the common father of src and dst */
638 *res_src = current_src; /* second the first different father of src */
639 *res_dst = current_dst; /* three the first different father of dst */
641 #undef ELEMENTS_FATHER_MAXDEPTH
644 /* Global Business methods */
647 * \brief Recursive function for get_route_latency
649 * \param src the source host name
650 * \param dst the destination host name
651 * \param *e_route the route where the links are stored
652 * \param *latency the latency, if needed
654 * This function is called by "get_route" and "get_latency". It allows to walk
655 * recursively through the routing components tree.
657 static void _get_route_latency(const char *src, const char *dst,
658 xbt_dynar_t *route, double *latency)
660 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
661 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
663 routing_component_t common_father;
664 routing_component_t src_father;
665 routing_component_t dst_father;
666 elements_father(src, dst, &common_father, &src_father, &dst_father);
668 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
670 route_extended_t e_route = NULL;
672 e_route = common_father->get_route(common_father, src, dst);
673 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
674 *route = e_route->generic_route.link_list;
677 *latency = common_father->get_latency(common_father, src, dst, e_route);
678 xbt_assert(*latency >= 0.0,
679 "latency error on route between \"%s\" and \"%s\"", src, dst);
682 xbt_free(e_route->src_gateway);
683 xbt_free(e_route->dst_gateway);
687 } else { /* SURF_ROUTING_RECURSIVE */
689 route_extended_t e_route_bypass = NULL;
690 if (common_father->get_bypass_route)
691 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
693 xbt_assert(!latency || !e_route_bypass,
694 "Bypass cannot work yet with get_latency");
696 route_extended_t e_route_cnt = e_route_bypass
698 : common_father->get_route(common_father,
699 src_father->name, dst_father->name);
701 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
702 src_father->name, dst_father->name);
704 xbt_assert((e_route_cnt->src_gateway == NULL) ==
705 (e_route_cnt->dst_gateway == NULL),
706 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
709 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
712 *latency = common_father->get_latency(common_father,
713 src_father->name, dst_father->name,
715 xbt_assert(*latency >= 0.0,
716 "latency error on route between \"%s\" and \"%s\"",
717 src_father->name, dst_father->name);
723 if (strcmp(src, e_route_cnt->src_gateway)) {
725 xbt_dynar_t route_src;
727 _get_route_latency(src, e_route_cnt->src_gateway,
728 (route ? &route_src : NULL),
729 (latency ? &latency_src : NULL));
731 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
732 src, e_route_cnt->src_gateway);
733 xbt_dynar_foreach(route_src, cpt, link) {
734 xbt_dynar_push(*route, &link);
736 xbt_dynar_free(&route_src);
739 xbt_assert(latency_src >= 0.0,
740 "latency error on route between \"%s\" and \"%s\"",
741 src, e_route_cnt->src_gateway);
742 *latency += latency_src;
747 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
748 xbt_dynar_push(*route, &link);
752 if (strcmp(e_route_cnt->dst_gateway, dst)) {
754 xbt_dynar_t route_dst;
756 _get_route_latency(e_route_cnt->dst_gateway, dst,
757 (route ? &route_dst : NULL),
758 (latency ? &latency_dst : NULL));
760 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
761 e_route_cnt->dst_gateway, dst);
762 xbt_dynar_foreach(route_dst, cpt, link) {
763 xbt_dynar_push(*route, &link);
765 xbt_dynar_free(&route_dst);
768 xbt_assert(latency_dst >= 0.0,
769 "latency error on route between \"%s\" and \"%s\"",
770 e_route_cnt->dst_gateway, dst);
771 *latency += latency_dst;
775 generic_free_extended_route(e_route_cnt);
780 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
782 static void get_route_latency(const char *src, const char *dst,
783 xbt_dynar_t *route, double *latency, int cleanup)
785 _get_route_latency(src, dst, route, latency);
786 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
787 xbt_assert(!latency || *latency >= 0.0,
788 "latency error on route between \"%s\" and \"%s\"", src, dst);
790 xbt_dynar_free(&global_routing->last_route);
791 global_routing->last_route = cleanup ? *route : NULL;
796 * \brief Generic method: find a route between hosts
798 * \param src the source host name
799 * \param dst the destination host name
801 * walk through the routing components tree and find a route between hosts
802 * by calling the differents "get_route" functions in each routing component.
803 * No need to free the returned dynar. It will be freed at the next call.
805 static xbt_dynar_t get_route(const char *src, const char *dst)
807 xbt_dynar_t route = NULL;
808 get_route_latency(src, dst, &route, NULL, 1);
813 * \brief Generic method: find a route between hosts
815 * \param src the source host name
816 * \param dst the destination host name
818 * walk through the routing components tree and find a route between hosts
819 * by calling the differents "get_route" functions in each routing component.
820 * Leaves the caller the responsability to clean the returned dynar.
822 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
824 xbt_dynar_t route = NULL;
825 get_route_latency(src, dst, &route, NULL, 0);
830 static double get_latency(const char *src, const char *dst)
832 double latency = -1.0;
833 get_route_latency(src, dst, NULL, &latency, 0);
838 * \brief Recursive function for finalize
840 * \param rc the source host name
842 * This fuction is call by "finalize". It allow to finalize the
843 * AS or routing components. It delete all the structures.
845 static void _finalize(routing_component_t rc)
848 xbt_dict_cursor_t cursor = NULL;
850 routing_component_t elem;
851 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
854 xbt_dict_t tmp_sons = rc->routing_sons;
855 char *tmp_name = rc->name;
856 xbt_dict_free(&tmp_sons);
858 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
859 current_routing->name);
860 (*(rc->finalize)) (rc);
865 * \brief Generic method: delete all the routing structures
867 * walk through the routing components tree and delete the structures
868 * by calling the differents "finalize" functions in each routing component
870 static void finalize(void)
872 /* delete recursibly all the tree */
873 _finalize(global_routing->root);
874 /* delete last_route */
875 xbt_dynar_free(&(global_routing->last_route));
876 /* delete global routing structure */
877 xbt_free(global_routing);
880 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
882 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
884 //adding my one link routes
887 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
889 xbt_dynar_foreach(onelink_mine, cpt, link) {
890 xbt_dynar_push(ret, &link);
895 xbt_dict_cursor_t cursor = NULL;
896 routing_component_t rc_child;
897 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
898 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
900 xbt_dynar_foreach(onelink_child, cpt, link) {
901 xbt_dynar_push(ret, &link);
908 static xbt_dynar_t get_onelink_routes(void)
910 return recursive_get_onelink_routes(global_routing->root);
913 e_surf_network_element_type_t get_network_element_type(const char
916 network_element_info_t rc = NULL;
918 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
919 if(rc) return rc->rc_type;
921 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
922 if(rc) return rc->rc_type;
924 return SURF_NETWORK_ELEMENT_NULL;
928 * \brief Generic method: create the global routing schema
930 * Make a global routing structure and set all the parsing functions.
932 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
934 /* config the uniq global routing */
935 global_routing = xbt_new0(s_routing_global_t, 1);
936 global_routing->root = NULL;
937 global_routing->get_route = get_route;
938 global_routing->get_latency = get_latency;
939 global_routing->get_route_no_cleanup = get_route_no_cleanup;
940 global_routing->get_onelink_routes = get_onelink_routes;
941 global_routing->get_route_latency = get_route_latency;
942 global_routing->get_network_element_type = get_network_element_type;
943 global_routing->finalize = finalize;
944 global_routing->loopback = loopback;
945 global_routing->size_of_link = size_of_links;
946 global_routing->last_route = NULL;
947 get_link_latency = get_link_latency_fun;
948 /* no current routing at moment */
949 current_routing = NULL;
951 /* parse generic elements */
952 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
953 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
954 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
956 surfxml_add_callback(STag_surfxml_route_cb_list,
957 &parse_S_route_new_and_endpoints_XML);
958 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
959 &parse_S_ASroute_new_and_endpoints);
960 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
961 &parse_S_bypassRoute_new_and_endpoints);
963 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
964 &parse_E_link_ctn_new_elem_XML);
966 surfxml_add_callback(ETag_surfxml_route_cb_list,
967 &parse_E_route_store_route);
968 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
969 &parse_E_ASroute_store_route);
970 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
971 &parse_E_bypassRoute_store_route);
973 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
974 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
976 surfxml_add_callback(STag_surfxml_cluster_cb_list,
977 &routing_parse_Scluster);
979 surfxml_add_callback(STag_surfxml_peer_cb_list,
980 &routing_parse_Speer);
982 surfxml_add_callback(ETag_surfxml_platform_cb_list,
986 instr_routing_define_callbacks();
990 void surf_parse_add_callback_config(void)
992 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
993 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
994 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
995 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
996 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
999 void surf_parse_models_setup()
1001 routing_parse_Erandom();
1002 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1003 surf_config_models_setup(platform_filename);
1004 free(platform_filename);
1007 /* ************************************************** */
1008 /* ********** PATERN FOR NEW ROUTING **************** */
1010 /* The minimal configuration of a new routing model need the next functions,
1011 * also you need to set at the start of the file, the new model in the model
1012 * list. Remember keep the null ending of the list.
1014 /*** Routing model structure ***/
1016 // s_routing_component_t generic_routing;
1017 // /* things that your routing model need */
1018 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1020 /*** Parse routing model functions ***/
1021 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1022 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1023 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1024 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1025 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1027 /*** Business methods ***/
1028 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1029 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1030 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1032 /*** Creation routing model functions ***/
1033 // static void* model_NEW_create(void) {
1034 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1035 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1036 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1037 // new_component->generic_routing.set_route = model_NEW_set_route;
1038 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1039 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1040 // new_component->generic_routing.get_route = NEW_get_route;
1041 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1042 // new_component->generic_routing.finalize = NEW_finalize;
1043 // /* initialization of internal structures */
1044 // return new_component;
1045 // } /* mandatory */
1046 // static void model_NEW_load(void) {} /* mandatory */
1047 // static void model_NEW_unload(void) {} /* mandatory */
1048 // static void model_NEW_end(void) {} /* mandatory */
1050 /* ************************************************************************** */
1051 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1053 void generic_set_processing_unit(routing_component_t rc,
1056 XBT_DEBUG("Load process unit \"%s\"", name);
1057 int *id = xbt_new0(int, 1);
1058 xbt_dict_t _to_index;
1059 _to_index = current_routing->to_index;
1060 *id = xbt_dict_length(_to_index);
1061 xbt_dict_set(_to_index, name, id, xbt_free);
1064 void generic_set_autonomous_system(routing_component_t rc,
1067 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1068 int *id = xbt_new0(int, 1);
1069 xbt_dict_t _to_index;
1070 _to_index = current_routing->to_index;
1071 *id = xbt_dict_length(_to_index);
1072 xbt_dict_set(_to_index, name, id, xbt_free);
1075 int surf_pointer_resource_cmp(const void *a, const void *b)
1080 int surf_link_resource_cmp(const void *a, const void *b)
1082 return !!memcmp(a,b,global_routing->size_of_link);
1085 void generic_set_bypassroute(routing_component_t rc,
1086 const char *src, const char *dst,
1087 route_extended_t e_route)
1089 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1090 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1093 route_name = bprintf("%s#%s", src, dst);
1094 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1095 "Invalid count of links, must be greater than zero (%s,%s)",
1097 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1098 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1099 src, e_route->src_gateway, dst, e_route->dst_gateway);
1101 route_extended_t new_e_route =
1102 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1103 xbt_dynar_free(&(e_route->generic_route.link_list));
1106 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1107 (void (*)(void *)) generic_free_extended_route);
1108 xbt_free(route_name);
1111 /* ************************************************************************** */
1112 /* *********************** GENERIC BUSINESS METHODS ************************* */
1114 double generic_get_link_latency(routing_component_t rc,
1115 const char *src, const char *dst,
1116 route_extended_t route)
1118 int need_to_clean = route?0:1;
1121 double latency = 0.0;
1123 route = route?route:rc->get_route(rc,src,dst);
1125 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1126 latency += get_link_latency(link);
1128 if(need_to_clean) generic_free_extended_route(route);
1132 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1134 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1137 route_extended_t generic_get_bypassroute(routing_component_t rc,
1141 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1142 routing_component_t src_as, dst_as;
1143 int index_src, index_dst;
1144 xbt_dynar_t path_src = NULL;
1145 xbt_dynar_t path_dst = NULL;
1146 routing_component_t current = NULL;
1147 routing_component_t *current_src = NULL;
1148 routing_component_t *current_dst = NULL;
1150 /* (1) find the as where the src and dst are located */
1151 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1152 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1153 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1154 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1156 if(src_data == NULL || dst_data == NULL)
1157 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1158 src, dst, rc->name);
1160 src_as = ((network_element_info_t)src_data)->rc_component;
1161 dst_as = ((network_element_info_t)dst_data)->rc_component;
1163 /* (2) find the path to the root routing component */
1164 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1166 while (current != NULL) {
1167 xbt_dynar_push(path_src, ¤t);
1168 current = current->routing_father;
1170 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1172 while (current != NULL) {
1173 xbt_dynar_push(path_dst, ¤t);
1174 current = current->routing_father;
1177 /* (3) find the common father */
1178 index_src = path_src->used - 1;
1179 index_dst = path_dst->used - 1;
1180 current_src = xbt_dynar_get_ptr(path_src, index_src);
1181 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1182 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1183 xbt_dynar_pop_ptr(path_src);
1184 xbt_dynar_pop_ptr(path_dst);
1187 current_src = xbt_dynar_get_ptr(path_src, index_src);
1188 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1191 int max_index_src = path_src->used - 1;
1192 int max_index_dst = path_dst->used - 1;
1194 int max_index = max(max_index_src, max_index_dst);
1197 route_extended_t e_route_bypass = NULL;
1199 for (max = 0; max <= max_index; max++) {
1200 for (i = 0; i < max; i++) {
1201 if (i <= max_index_src && max <= max_index_dst) {
1202 char *route_name = bprintf("%s#%s",
1203 (*(routing_component_t *)
1205 (path_src, i)))->name,
1206 (*(routing_component_t *)
1208 (path_dst, max)))->name);
1210 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1211 xbt_free(route_name);
1215 if (max <= max_index_src && i <= max_index_dst) {
1216 char *route_name = bprintf("%s#%s",
1217 (*(routing_component_t *)
1219 (path_src, max)))->name,
1220 (*(routing_component_t *)
1222 (path_dst, i)))->name);
1224 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1225 xbt_free(route_name);
1234 if (max <= max_index_src && max <= max_index_dst) {
1235 char *route_name = bprintf("%s#%s",
1236 (*(routing_component_t *)
1238 (path_src, max)))->name,
1239 (*(routing_component_t *)
1241 (path_dst, max)))->name);
1242 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1243 xbt_free(route_name);
1249 xbt_dynar_free(&path_src);
1250 xbt_dynar_free(&path_dst);
1252 route_extended_t new_e_route = NULL;
1254 if (e_route_bypass) {
1256 unsigned int cpt = 0;
1257 new_e_route = xbt_new0(s_route_extended_t, 1);
1258 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1259 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1260 new_e_route->generic_route.link_list =
1261 xbt_dynar_new(global_routing->size_of_link, NULL);
1262 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1263 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1270 /* ************************************************************************** */
1271 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1274 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1275 void *data, int order)
1281 xbt_dynar_t links = NULL, links_id = NULL;
1283 new_route = xbt_new0(s_route_t, 1);
1284 new_route->link_list =
1285 xbt_dynar_new(global_routing->size_of_link, NULL);
1287 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1288 "the hierarchy type is not SURF_ROUTING_BASE");
1290 links = ((route_t) data)->link_list;
1293 links_id = new_route->link_list;
1295 xbt_dynar_foreach(links, cpt, link_name) {
1298 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1301 xbt_dynar_push(links_id, &link);
1303 xbt_dynar_unshift(links_id, &link);
1305 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1312 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1313 void *data, int order)
1317 route_extended_t e_route, new_e_route;
1320 xbt_dynar_t links = NULL, links_id = NULL;
1322 new_e_route = xbt_new0(s_route_extended_t, 1);
1323 new_e_route->generic_route.link_list =
1324 xbt_dynar_new(global_routing->size_of_link, NULL);
1325 new_e_route->src_gateway = NULL;
1326 new_e_route->dst_gateway = NULL;
1328 xbt_assert(hierarchy == SURF_ROUTING_BASE
1329 || hierarchy == SURF_ROUTING_RECURSIVE,
1330 "the hierarchy type is not defined");
1332 if (hierarchy == SURF_ROUTING_BASE) {
1334 route = (route_t) data;
1335 links = route->link_list;
1337 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1339 e_route = (route_extended_t) data;
1340 xbt_assert(e_route->src_gateway
1341 && e_route->dst_gateway, "bad gateway, is null");
1342 links = e_route->generic_route.link_list;
1344 /* remeber not erase the gateway names */
1345 new_e_route->src_gateway = strdup(e_route->src_gateway);
1346 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1349 links_id = new_e_route->generic_route.link_list;
1351 xbt_dynar_foreach(links, cpt, link_name) {
1354 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1357 xbt_dynar_push(links_id, &link);
1359 xbt_dynar_unshift(links_id, &link);
1361 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1367 void generic_free_route(route_t route)
1370 xbt_dynar_free(&(route->link_list));
1375 void generic_free_extended_route(route_extended_t e_route)
1378 xbt_dynar_free(&(e_route->generic_route.link_list));
1379 if (e_route->src_gateway)
1380 xbt_free(e_route->src_gateway);
1381 if (e_route->dst_gateway)
1382 xbt_free(e_route->dst_gateway);
1387 static routing_component_t generic_as_exist(routing_component_t find_from,
1388 routing_component_t to_find)
1390 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1391 xbt_dict_cursor_t cursor = NULL;
1394 routing_component_t elem;
1395 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1396 if (to_find == elem || generic_as_exist(elem, to_find)) {
1407 generic_autonomous_system_exist(routing_component_t rc, char *element)
1409 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1410 routing_component_t element_as, result, elem;
1411 xbt_dict_cursor_t cursor = NULL;
1413 element_as = ((network_element_info_t)
1414 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1415 result = ((routing_component_t) - 1);
1416 if (element_as != rc)
1417 result = generic_as_exist(rc, element_as);
1421 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1422 found = !strcmp(elem->name, element);
1433 generic_processing_units_exist(routing_component_t rc, char *element)
1435 routing_component_t element_as;
1436 element_as = ((network_element_info_t)
1437 xbt_lib_get_or_null(host_lib,
1438 element, ROUTING_HOST_LEVEL))->rc_component;
1439 if (element_as == rc)
1441 return generic_as_exist(rc, element_as);
1444 void generic_src_dst_check(routing_component_t rc, const char *src,
1448 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1449 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1450 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1451 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1453 if(src_data == NULL || dst_data == NULL)
1454 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1455 src, dst, rc->name);
1457 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1458 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1460 if(src_as != dst_as)
1461 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1462 src, src_as->name, dst, dst_as->name);
1464 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1465 src,dst,src_as->name, dst_as->name,rc->name);
1468 static void routing_parse_Sconfig(void)
1470 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1473 static void routing_parse_Econfig(void)
1475 xbt_dict_cursor_t cursor = NULL;
1479 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1480 cfg = bprintf("%s:%s",key,elem);
1481 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1482 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1484 XBT_INFO("The custom configuration '%s' is already define by user!",key);
1487 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1490 void routing_parse_Scluster(void)
1492 static int AX_ptr = 0;
1494 char *cluster_id = A_surfxml_cluster_id;
1495 char *cluster_prefix = A_surfxml_cluster_prefix;
1496 char *cluster_suffix = A_surfxml_cluster_suffix;
1497 char *cluster_radical = A_surfxml_cluster_radical;
1498 char *cluster_power = A_surfxml_cluster_power;
1499 char *cluster_core = A_surfxml_cluster_core;
1500 char *cluster_bw = A_surfxml_cluster_bw;
1501 char *cluster_lat = A_surfxml_cluster_lat;
1502 char *temp_cluster_bw = NULL;
1503 char *temp_cluster_lat = NULL;
1504 char *temp_cluster_power = NULL;
1505 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1506 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1507 char *cluster_availability_file = A_surfxml_cluster_availability_file;
1508 char *cluster_state_file = A_surfxml_cluster_state_file;
1509 char *host_id, *groups, *link_id = NULL;
1511 char *availability_file = xbt_strdup(cluster_availability_file);
1512 char *state_file = xbt_strdup(cluster_state_file);
1514 if(xbt_dict_size(patterns)==0)
1515 patterns = xbt_dict_new();
1517 xbt_dict_set(patterns,"id",cluster_id,NULL);
1518 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
1519 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
1521 #ifdef HAVE_PCRE_LIB
1522 char *route_src_dst;
1526 xbt_dynar_t radical_elements;
1527 xbt_dynar_t radical_ends;
1528 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
1529 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
1531 #ifndef HAVE_PCRE_LIB
1532 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
1533 char *route_src, *route_dst;
1537 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1538 static unsigned int surfxml_buffer_stack_stack[1024];
1540 surfxml_buffer_stack_stack[0] = 0;
1542 surfxml_bufferstack_push(1);
1544 SURFXML_BUFFER_SET(AS_id, cluster_id);
1545 #ifdef HAVE_PCRE_LIB
1546 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
1547 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
1549 SURFXML_BUFFER_SET(AS_routing, "Full");
1550 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
1552 SURFXML_START_TAG(AS);
1554 radical_elements = xbt_str_split(cluster_radical, ",");
1555 xbt_dynar_foreach(radical_elements, iter, groups) {
1556 radical_ends = xbt_str_split(groups, "-");
1557 switch (xbt_dynar_length(radical_ends)) {
1559 surf_parse_get_int(&start,
1560 xbt_dynar_get_as(radical_ends, 0, char *));
1561 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
1562 #ifndef HAVE_PCRE_LIB
1563 xbt_dynar_push_as(tab_elements_num, int, start);
1565 link_id = bprintf("%s_link_%d", cluster_id, start);
1567 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1568 temp_cluster_power = xbt_strdup(cluster_power);
1569 temp_cluster_power = replace_random_parameter(temp_cluster_power);
1570 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1571 A_surfxml_host_state = A_surfxml_host_state_ON;
1572 SURFXML_BUFFER_SET(host_id, host_id);
1573 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1574 SURFXML_BUFFER_SET(host_core, cluster_core);
1575 SURFXML_BUFFER_SET(host_availability, "1.0");
1576 SURFXML_BUFFER_SET(host_coordinates, "");
1577 xbt_free(availability_file);
1578 availability_file = xbt_strdup(cluster_availability_file);
1579 xbt_free(state_file);
1580 state_file = xbt_strdup(cluster_state_file);
1581 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1582 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1583 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1584 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1585 XBT_DEBUG("</host>");
1586 SURFXML_START_TAG(host);
1587 SURFXML_END_TAG(host);
1590 temp_cluster_bw = xbt_strdup(cluster_bw);
1591 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1592 temp_cluster_lat = xbt_strdup(cluster_lat);
1593 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1594 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1595 A_surfxml_link_state = A_surfxml_link_state_ON;
1596 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1597 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1598 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1599 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1600 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1601 SURFXML_BUFFER_SET(link_id, link_id);
1602 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1603 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1604 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1605 SURFXML_BUFFER_SET(link_latency_file, "");
1606 SURFXML_BUFFER_SET(link_state_file, "");
1607 SURFXML_START_TAG(link);
1608 SURFXML_END_TAG(link);
1610 xbt_free(temp_cluster_bw);
1611 xbt_free(temp_cluster_lat);
1612 xbt_free(temp_cluster_power);
1619 surf_parse_get_int(&start,
1620 xbt_dynar_get_as(radical_ends, 0, char *));
1621 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1622 for (i = start; i <= end; i++) {
1623 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
1624 #ifndef HAVE_PCRE_LIB
1625 xbt_dynar_push_as(tab_elements_num, int, i);
1627 link_id = bprintf("%s_link_%d", cluster_id, i);
1629 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1630 temp_cluster_power = xbt_strdup(cluster_power);
1631 temp_cluster_power = replace_random_parameter(temp_cluster_power);
1632 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1633 A_surfxml_host_state = A_surfxml_host_state_ON;
1634 SURFXML_BUFFER_SET(host_id, host_id);
1635 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1636 SURFXML_BUFFER_SET(host_core, cluster_core);
1637 SURFXML_BUFFER_SET(host_availability, "1.0");
1638 SURFXML_BUFFER_SET(host_coordinates, "");
1639 xbt_free(availability_file);
1640 availability_file = xbt_strdup(cluster_availability_file);
1641 xbt_free(state_file);
1642 state_file = xbt_strdup(cluster_state_file);
1643 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1644 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1645 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1646 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1647 XBT_DEBUG("</host>");
1648 SURFXML_START_TAG(host);
1649 SURFXML_END_TAG(host);
1651 xbt_free(temp_cluster_power);
1653 temp_cluster_bw = xbt_strdup(cluster_bw);
1654 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1655 temp_cluster_lat = xbt_strdup(cluster_lat);
1656 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1657 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1658 A_surfxml_link_state = A_surfxml_link_state_ON;
1659 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1660 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1661 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1662 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1663 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1664 SURFXML_BUFFER_SET(link_id, link_id);
1665 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1666 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1667 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1668 SURFXML_BUFFER_SET(link_latency_file, "");
1669 SURFXML_BUFFER_SET(link_state_file, "");
1670 SURFXML_START_TAG(link);
1671 SURFXML_END_TAG(link);
1673 xbt_free(temp_cluster_bw);
1674 xbt_free(temp_cluster_lat);
1681 XBT_DEBUG("Malformed radical");
1684 xbt_dynar_free(&radical_ends);
1686 xbt_dynar_free(&radical_elements);
1690 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
1693 XBT_DEBUG("<router id=\"%s\"/>", router_id);
1694 SURFXML_BUFFER_SET(router_id, router_id);
1695 SURFXML_BUFFER_SET(router_coordinates, "");
1696 SURFXML_START_TAG(router);
1697 SURFXML_END_TAG(router);
1699 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1700 char *link_backbone = bprintf("%s_backbone", cluster_id);
1701 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
1702 A_surfxml_link_state = A_surfxml_link_state_ON;
1703 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1704 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1705 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1706 SURFXML_BUFFER_SET(link_id, link_backbone);
1707 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
1708 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
1709 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1710 SURFXML_BUFFER_SET(link_latency_file, "");
1711 SURFXML_BUFFER_SET(link_state_file, "");
1712 SURFXML_START_TAG(link);
1713 SURFXML_END_TAG(link);
1714 free(link_backbone);
1719 #ifdef HAVE_PCRE_LIB
1720 char *new_suffix = xbt_strdup("");
1722 radical_elements = xbt_str_split(cluster_suffix, ".");
1723 xbt_dynar_foreach(radical_elements, iter, groups) {
1724 if (strcmp(groups, "")) {
1725 char *old_suffix = new_suffix;
1726 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1730 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
1731 xbt_dynar_free(&radical_elements);
1734 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
1735 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
1736 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
1738 //from router to router
1739 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, router_id);
1740 XBT_DEBUG("symmetrical=\"NO\">");
1741 SURFXML_BUFFER_SET(route_src, router_id);
1742 SURFXML_BUFFER_SET(route_dst, router_id);
1743 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1744 SURFXML_START_TAG(route);
1746 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1747 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1748 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1749 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1750 SURFXML_START_TAG(link_ctn);
1751 SURFXML_END_TAG(link_ctn);
1754 XBT_DEBUG("</route>");
1755 SURFXML_END_TAG(route);
1757 //from host to router
1758 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, router_id);
1759 XBT_DEBUG("symmetrical=\"NO\">");
1760 SURFXML_BUFFER_SET(route_src, route_src_dst);
1761 SURFXML_BUFFER_SET(route_dst, router_id);
1762 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1763 SURFXML_START_TAG(route);
1765 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1766 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1767 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1768 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1769 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1770 SURFXML_START_TAG(link_ctn);
1771 SURFXML_END_TAG(link_ctn);
1773 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1774 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1775 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1776 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1777 SURFXML_START_TAG(link_ctn);
1778 SURFXML_END_TAG(link_ctn);
1781 XBT_DEBUG("</route>");
1782 SURFXML_END_TAG(route);
1784 //from router to host
1785 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, route_src_dst);
1786 XBT_DEBUG("symmetrical=\"NO\">");
1787 SURFXML_BUFFER_SET(route_src, router_id);
1788 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1789 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1790 SURFXML_START_TAG(route);
1792 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1793 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1794 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1795 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1796 SURFXML_START_TAG(link_ctn);
1797 SURFXML_END_TAG(link_ctn);
1800 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1801 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1802 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1803 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1804 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1805 SURFXML_START_TAG(link_ctn);
1806 SURFXML_END_TAG(link_ctn);
1808 XBT_DEBUG("</route>");
1809 SURFXML_END_TAG(route);
1812 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
1813 XBT_DEBUG("symmetrical=\"NO\">");
1814 SURFXML_BUFFER_SET(route_src, route_src_dst);
1815 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1816 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1817 SURFXML_START_TAG(route);
1819 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1820 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1821 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1822 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1823 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1824 SURFXML_START_TAG(link_ctn);
1825 SURFXML_END_TAG(link_ctn);
1827 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1828 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1829 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1830 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1831 SURFXML_START_TAG(link_ctn);
1832 SURFXML_END_TAG(link_ctn);
1835 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1836 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1837 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1838 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1839 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1840 SURFXML_START_TAG(link_ctn);
1841 SURFXML_END_TAG(link_ctn);
1843 XBT_DEBUG("</route>");
1844 SURFXML_END_TAG(route);
1846 free(pcre_link_dst);
1847 free(pcre_link_backbone);
1848 free(pcre_link_src);
1849 free(route_src_dst);
1852 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
1853 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
1854 if (i == xbt_dynar_length(tab_elements_num)) {
1855 route_src = router_id;
1858 bprintf("%s%d%s", cluster_prefix,
1859 xbt_dynar_get_as(tab_elements_num, i, int),
1863 if (j == xbt_dynar_length(tab_elements_num)) {
1864 route_dst = router_id;
1867 bprintf("%s%d%s", cluster_prefix,
1868 xbt_dynar_get_as(tab_elements_num, j, int),
1872 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
1873 XBT_DEBUG("symmetrical=\"NO\">");
1874 SURFXML_BUFFER_SET(route_src, route_src);
1875 SURFXML_BUFFER_SET(route_dst, route_dst);
1876 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1877 SURFXML_START_TAG(route);
1879 if (i != xbt_dynar_length(tab_elements_num)){
1881 bprintf("%s_link_%d", cluster_id,
1882 xbt_dynar_get_as(tab_elements_num, i, int));
1883 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_src);
1884 SURFXML_BUFFER_SET(link_ctn_id, route_src);
1885 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1886 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1887 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1888 SURFXML_START_TAG(link_ctn);
1889 SURFXML_END_TAG(link_ctn);
1893 if(strcmp(cluster_bb_bw,"") && strcmp(cluster_bb_lat,"")){
1894 XBT_DEBUG("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
1895 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
1896 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1897 SURFXML_START_TAG(link_ctn);
1898 SURFXML_END_TAG(link_ctn);
1901 if (j != xbt_dynar_length(tab_elements_num)) {
1903 bprintf("%s_link_%d", cluster_id,
1904 xbt_dynar_get_as(tab_elements_num, j, int));
1905 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_dst);
1906 SURFXML_BUFFER_SET(link_ctn_id, route_dst);
1907 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1908 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1909 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1910 SURFXML_START_TAG(link_ctn);
1911 SURFXML_END_TAG(link_ctn);
1915 XBT_DEBUG("</route>");
1916 SURFXML_END_TAG(route);
1919 xbt_dynar_free(&tab_elements_num);
1924 xbt_dict_free(&patterns);
1925 free(availability_file);
1929 SURFXML_END_TAG(AS);
1932 surfxml_bufferstack_pop(1);
1935 * This function take a string and replace parameters from patterns dict.
1936 * It returns the new value.
1938 static char* replace_random_parameter(char * string)
1940 char *test_string = NULL;
1942 if(xbt_dict_size(random_value)==0)
1945 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1946 test_string = bprintf("${%s}", string);
1947 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1949 if (strcmp(test_string,"")) { //if not empty, keep this value.
1951 string = test_string;
1952 } //In other case take old value (without ${})
1958 static void clean_dict_random(void)
1960 xbt_dict_free(&random_value);
1961 xbt_dict_free(&patterns);
1964 static void routing_parse_Speer(void)
1966 static int AX_ptr = 0;
1968 char *peer_id = A_surfxml_peer_id;
1969 char *peer_power = A_surfxml_peer_power;
1970 char *peer_bw_in = A_surfxml_peer_bw_in;
1971 char *peer_bw_out = A_surfxml_peer_bw_out;
1972 char *peer_lat = A_surfxml_peer_lat;
1973 char *peer_coord = A_surfxml_peer_coordinates;
1974 char *peer_state_file = A_surfxml_peer_state_file;
1975 char *peer_availability_file = A_surfxml_peer_availability_file;
1977 char *host_id = NULL;
1978 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1980 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1981 static unsigned int surfxml_buffer_stack_stack[1024];
1983 surfxml_buffer_stack_stack[0] = 0;
1985 surfxml_bufferstack_push(1);
1987 SURFXML_BUFFER_SET(AS_id, peer_id);
1989 SURFXML_BUFFER_SET(AS_routing, "Full");
1990 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
1992 SURFXML_START_TAG(AS);
1995 host_id = bprintf("peer_%s", peer_id);
1996 router_id = bprintf("router_%s", peer_id);
1997 link_id_up = bprintf("link_%s_up", peer_id);
1998 link_id_down = bprintf("link_%s_down", peer_id);
2000 link_router = bprintf("%s_link_router", peer_id);
2001 link_backbone = bprintf("%s_backbone", peer_id);
2003 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
2004 A_surfxml_host_state = A_surfxml_host_state_ON;
2005 SURFXML_BUFFER_SET(host_id, host_id);
2006 SURFXML_BUFFER_SET(host_power, peer_power);
2007 SURFXML_BUFFER_SET(host_availability, "1.0");
2008 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
2009 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
2010 SURFXML_BUFFER_SET(host_coordinates, "");
2011 SURFXML_START_TAG(host);
2012 SURFXML_END_TAG(host);
2014 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
2015 SURFXML_BUFFER_SET(router_id, router_id);
2016 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
2017 SURFXML_START_TAG(router);
2018 SURFXML_END_TAG(router);
2020 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
2021 A_surfxml_link_state = A_surfxml_link_state_ON;
2022 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2023 SURFXML_BUFFER_SET(link_id, link_id_up);
2024 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
2025 SURFXML_BUFFER_SET(link_latency, peer_lat);
2026 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2027 SURFXML_BUFFER_SET(link_latency_file, "");
2028 SURFXML_BUFFER_SET(link_state_file, "");
2029 SURFXML_START_TAG(link);
2030 SURFXML_END_TAG(link);
2032 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
2033 A_surfxml_link_state = A_surfxml_link_state_ON;
2034 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2035 SURFXML_BUFFER_SET(link_id, link_id_down);
2036 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
2037 SURFXML_BUFFER_SET(link_latency, peer_lat);
2038 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2039 SURFXML_BUFFER_SET(link_latency_file, "");
2040 SURFXML_BUFFER_SET(link_state_file, "");
2041 SURFXML_START_TAG(link);
2042 SURFXML_END_TAG(link);
2047 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
2048 XBT_DEBUG("symmetrical=\"NO\">");
2049 SURFXML_BUFFER_SET(route_src, host_id);
2050 SURFXML_BUFFER_SET(route_dst, router_id);
2051 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2052 SURFXML_START_TAG(route);
2054 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
2055 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
2056 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2057 SURFXML_START_TAG(link_ctn);
2058 SURFXML_END_TAG(link_ctn);
2060 XBT_DEBUG("</route>");
2061 SURFXML_END_TAG(route);
2064 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
2065 XBT_DEBUG("symmetrical=\"NO\">");
2066 SURFXML_BUFFER_SET(route_src, router_id);
2067 SURFXML_BUFFER_SET(route_dst, host_id);
2068 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2069 SURFXML_START_TAG(route);
2071 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
2072 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
2073 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2074 SURFXML_START_TAG(link_ctn);
2075 SURFXML_END_TAG(link_ctn);
2077 XBT_DEBUG("</route>");
2078 SURFXML_END_TAG(route);
2081 SURFXML_END_TAG(AS);
2084 //xbt_dynar_free(&tab_elements_num);
2088 free(link_backbone);
2091 surfxml_bufferstack_pop(1);
2094 static void routing_parse_Srandom(void)
2096 double mean, std, min, max, seed;
2097 char *random_id = A_surfxml_random_id;
2098 char *random_radical = A_surfxml_random_radical;
2099 char *rd_name = NULL;
2101 surf_parse_get_double(&mean,A_surfxml_random_mean);
2102 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2103 surf_parse_get_double(&min,A_surfxml_random_min);
2104 surf_parse_get_double(&max,A_surfxml_random_max);
2105 surf_parse_get_double(&seed,A_surfxml_random_seed);
2109 random_data_t random = xbt_new0(s_random_data_t, 1);
2112 xbt_dynar_t radical_elements;
2116 xbt_dynar_t radical_ends;
2118 random->generator = A_surfxml_random_generator;
2119 random->seed = seed;
2123 /* Check user stupidities */
2125 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2127 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2130 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2133 /* normalize the mean and standard deviation before storing */
2134 random->mean = (mean - min) / (max - min);
2135 random->std = std / (max - min);
2137 if (random->mean * (1 - random->mean) < random->std * random->std)
2138 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2139 random->mean, random->std);
2141 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2151 if(xbt_dict_size(random_value)==0)
2152 random_value = xbt_dict_new();
2154 if(!strcmp(random_radical,""))
2156 res = random_generate(random);
2157 rd_value = bprintf("%f",res);
2158 xbt_dict_set(random_value, random_id, rd_value, free);
2162 radical_elements = xbt_str_split(random_radical, ",");
2163 xbt_dynar_foreach(radical_elements, iter, groups) {
2164 radical_ends = xbt_str_split(groups, "-");
2165 switch (xbt_dynar_length(radical_ends)) {
2167 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2168 res = random_generate(random);
2169 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2170 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2174 case 2: surf_parse_get_int(&start,
2175 xbt_dynar_get_as(radical_ends, 0, char *));
2176 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2177 for (i = start; i <= end; i++) {
2178 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2179 res = random_generate(random);
2180 tmpbuf = bprintf("%s%d",random_id,i);
2181 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2186 XBT_INFO("Malformed radical");
2188 res = random_generate(random);
2189 rd_name = bprintf("%s_router",random_id);
2190 rd_value = bprintf("%f",res);
2191 xbt_dict_set(random_value, rd_name, rd_value, free);
2193 xbt_dynar_free(&radical_ends);
2196 xbt_dynar_free(&radical_elements);
2200 static void routing_parse_Erandom(void)
2202 xbt_dict_cursor_t cursor = NULL;
2206 xbt_dict_foreach(random_value, cursor, key, elem) {
2207 XBT_DEBUG("%s = %s",key,elem);
2214 * New methods to init the routing model component from the lua script
2218 * calling parse_S_AS_lua with lua values
2220 void routing_AS_init(const char *AS_id, const char *AS_routing)
2222 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
2226 * calling parse_E_AS_lua to fisnish the creation of routing component
2228 void routing_AS_end(const char *AS_id)
2230 parse_E_AS_lua((char *) AS_id);
2234 * add a host to the network element list
2237 void routing_add_host(const char *host_id)
2239 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2243 * Set a new link on the actual list of link for a route or ASroute
2245 void routing_add_link(const char *link_id)
2247 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2251 *Set the endpoints for a route
2253 void routing_set_route(const char *src_id, const char *dst_id)
2255 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2259 * Store the route by calling parse_E_route_store_route
2261 void routing_store_route(void)
2263 parse_E_route_store_route();