1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <pcre.h> /* regular expression library */
8 #include "surf_routing_private.h"
9 #include "surf/surf_routing.h"
10 #include "surf/surfxml_parse_values.h"
13 int ROUTING_HOST_LEVEL; //Routing level
14 int SURF_CPU_LEVEL; //Surf cpu level
15 int SURF_WKS_LEVEL; //Surf workstation level
16 int SIMIX_HOST_LEVEL; //Simix level
17 int MSG_HOST_LEVEL; //Msg level
18 int SD_HOST_LEVEL; //Simdag level
19 int COORD_HOST_LEVEL; //Coordinates level
20 int NS3_HOST_LEVEL; //host node for ns3
23 int SD_LINK_LEVEL; //Simdag level
24 int SURF_LINK_LEVEL; //Surf level
25 int NS3_LINK_LEVEL; //link for ns3
27 xbt_lib_t as_router_lib;
28 int ROUTING_ASR_LEVEL; //Routing level
29 int COORD_ASR_LEVEL; //Coordinates level
30 int NS3_ASR_LEVEL; //host node for ns3
32 static xbt_dict_t patterns = NULL;
33 static xbt_dict_t random_value = NULL;
36 routing_global_t global_routing = NULL;
37 routing_component_t current_routing = NULL;
38 model_type_t current_routing_model = NULL;
40 /* global parse functions */
41 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
42 static const char *src = NULL; /* temporary store the source name of a route */
43 static const char *dst = NULL; /* temporary store the destination name of a route */
44 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
45 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
46 static double_f_cpvoid_t get_link_latency = NULL;
48 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
50 static void routing_parse_Speer(void); /* peer bypass */
51 static void routing_parse_Srandom(void); /* random bypass */
52 static void routing_parse_Erandom(void); /* random bypass */
54 static void routing_parse_Sconfig(void); /* config Tag */
55 static void routing_parse_Econfig(void); /* config Tag */
57 static char* replace_random_parameter(char * chaine);
58 static void clean_dict_random(void);
60 /* this lines are only for replace use like index in the model table */
65 SURF_MODEL_DIJKSTRACACHE,
70 struct s_model_type routing_models[] = { {"Full",
71 "Full routing data (fast, large memory requirements, fully expressive)",
77 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
78 model_floyd_create, model_floyd_load, model_floyd_unload,
81 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
82 model_dijkstra_create, model_dijkstra_both_load,
83 model_dijkstra_both_unload, model_dijkstra_both_end},
85 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
86 model_dijkstracache_create, model_dijkstra_both_load,
87 model_dijkstra_both_unload, model_dijkstra_both_end},
88 {"none", "No routing (usable with Constant network only)",
89 model_none_create, model_none_load, model_none_unload, model_none_end},
90 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
91 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
92 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
93 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
94 {NULL, NULL, NULL, NULL, NULL, NULL}
97 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
99 double src_coord, dst_coord;
101 src_coord = atof(xbt_dynar_get_as(src, index, char *));
102 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
104 return (src_coord-dst_coord)*(src_coord-dst_coord);
108 static double base_vivaldi_get_latency (const char *src, const char *dst)
110 double euclidean_dist;
111 xbt_dynar_t src_ctn, dst_ctn;
112 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
113 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
114 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
115 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
117 if(dst_ctn == NULL || src_ctn == NULL)
118 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
120 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
121 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
123 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
126 return euclidean_dist / 1000;
129 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
131 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
132 int need_to_clean = e_route?0:1;
134 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
135 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
136 if(need_to_clean) generic_free_extended_route(e_route);
139 return base_vivaldi_get_latency(src,dst);
144 * \brief Add a "host" to the network element list
146 static void parse_S_host(const char *host_id, const char* coord)
148 network_element_info_t info = NULL;
149 if (current_routing->hierarchy == SURF_ROUTING_NULL)
150 current_routing->hierarchy = SURF_ROUTING_BASE;
151 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
152 "Reading a host, processing unit \"%s\" already exists",
154 xbt_assert(current_routing->set_processing_unit,
155 "no defined method \"set_processing_unit\" in \"%s\"",
156 current_routing->name);
157 (*(current_routing->set_processing_unit)) (current_routing, host_id);
158 info = xbt_new0(s_network_element_info_t, 1);
159 info->rc_component = current_routing;
160 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
161 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
162 if (strcmp(coord,"")) {
163 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
164 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
165 xbt_dynar_shrink(ctn, 0);
166 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
170 static void parse_E_host(void)
172 xbt_dict_cursor_t cursor = NULL;
176 xbt_dict_foreach(current_property_set, cursor, key, elem) {
177 XBT_DEBUG("property : %s = %s",key,elem);
182 * \brief Add a host to the network element list from XML
184 static void parse_S_host_XML(void)
186 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
188 static void parse_E_host_XML(void)
194 * \brief Add a host to the network element list from lua script
196 static void parse_S_host_lua(const char *host_id, const char *coord)
198 parse_S_host(host_id, coord);
203 * \brief Add a "router" to the network element list
205 static void parse_S_router(void)
207 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,struct_router->V_router_id, ROUTING_ASR_LEVEL),
211 "Reading a router, processing unit \"%s\" already exists",
212 struct_router->V_router_id);
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,
217 struct_router->V_router_id);
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,struct_router->V_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,struct_router->V_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();
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 struct_router->V_router_id = xbt_strdup(router_id);
245 struct_router->V_router_coord = xbt_strdup("");
246 return parse_S_router();
250 * \brief Set the endponints for a route
252 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
254 if (src != NULL && dst != NULL && link_list != NULL)
255 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
259 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
260 "Some limits are null in the route between \"%s\" and \"%s\"",
262 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
266 * \brief Set the endpoints for a route from XML
268 static void parse_S_route_new_and_endpoints_XML(void)
270 parse_S_route_new_and_endpoints(A_surfxml_route_src,
271 A_surfxml_route_dst);
275 * \brief Set the endpoints for a route from lua
277 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
279 parse_S_route_new_and_endpoints(id_src, id_dst);
283 * \brief Set the endponints and gateways for a ASroute
285 static void parse_S_ASroute_new_and_endpoints(void)
287 if (src != NULL && dst != NULL && link_list != NULL)
288 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
289 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
290 src = A_surfxml_ASroute_src;
291 dst = A_surfxml_ASroute_dst;
292 gw_src = A_surfxml_ASroute_gw_src;
293 gw_dst = A_surfxml_ASroute_gw_dst;
294 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
295 || strlen(gw_dst) > 0,
296 "Some limits are null in the route between \"%s\" and \"%s\"",
298 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
302 * \brief Set the endponints for a bypassRoute
304 static void parse_S_bypassRoute_new_and_endpoints(void)
306 if (src != NULL && dst != NULL && link_list != NULL)
308 "Bypass Route between %s to %s can not be defined",
309 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
310 src = A_surfxml_bypassRoute_src;
311 dst = A_surfxml_bypassRoute_dst;
312 gw_src = A_surfxml_bypassRoute_gw_src;
313 gw_dst = A_surfxml_bypassRoute_gw_dst;
314 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
315 || strlen(gw_dst) > 0,
316 "Some limits are null in the route between \"%s\" and \"%s\"",
318 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
322 * \brief Set a new link on the actual list of link for a route or ASroute
324 static void parse_E_link_ctn_new_elem(const char *link_id)
327 val = xbt_strdup(link_id);
328 xbt_dynar_push(link_list, &val);
332 * \brief Set a new link on the actual list of link for a route or ASroute from XML
335 static void parse_E_link_ctn_new_elem_XML(void)
337 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
338 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
339 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
340 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
341 parse_E_link_ctn_new_elem(link_id);
344 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
345 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
346 parse_E_link_ctn_new_elem(link_id);
352 * \brief Set a new link on the actual list of link for a route or ASroute from lua
354 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
356 parse_E_link_ctn_new_elem(link_id);
360 * \brief Store the route by calling the set_route function of the current routing component
362 static void parse_E_route_store_route(void)
364 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
365 route->generic_route.link_list = link_list;
366 xbt_assert(current_routing->set_route,
367 "no defined method \"set_route\" in \"%s\"",
368 current_routing->name);
369 (*(current_routing->set_route)) (current_routing, src, dst, route);
376 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
378 static void parse_E_ASroute_store_route(void)
380 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
381 e_route->generic_route.link_list = link_list;
382 e_route->src_gateway = xbt_strdup(gw_src);
383 e_route->dst_gateway = xbt_strdup(gw_dst);
384 xbt_assert(current_routing->set_ASroute,
385 "no defined method \"set_ASroute\" in \"%s\"",
386 current_routing->name);
387 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
396 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
398 static void parse_E_bypassRoute_store_route(void)
400 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
401 e_route->generic_route.link_list = link_list;
402 e_route->src_gateway = xbt_strdup(gw_src);
403 e_route->dst_gateway = xbt_strdup(gw_dst);
404 xbt_assert(current_routing->set_bypassroute,
405 "no defined method \"set_bypassroute\" in \"%s\"",
406 current_routing->name);
407 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
417 * \brief Make a new routing component
419 * make the new structure and
420 * set the parsing functions to allows parsing the part of the routing tree
422 void routing_AS_init(const char *AS_id, const char *AS_routing)
424 routing_component_t new_routing;
425 model_type_t model = NULL;
426 const char *wanted = AS_routing;
428 /* search the routing model */
429 for (cpt = 0; routing_models[cpt].name; cpt++)
430 if (!strcmp(wanted, routing_models[cpt].name))
431 model = &routing_models[cpt];
432 /* if its not exist, error */
434 fprintf(stderr, "Routing model %s not found. Existing models:\n",
436 for (cpt = 0; routing_models[cpt].name; cpt++)
437 if (!strcmp(wanted, routing_models[cpt].name))
438 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
439 routing_models[cpt].desc);
443 /* make a new routing component */
444 new_routing = (routing_component_t) (*(model->create)) ();
445 new_routing->routing = model;
446 new_routing->hierarchy = SURF_ROUTING_NULL;
447 new_routing->name = xbt_strdup(AS_id);
448 new_routing->routing_sons = xbt_dict_new();
450 /* Hack for Vivaldi */
451 if(!strcmp(model->name,"Vivaldi"))
452 new_routing->get_latency = vivaldi_get_link_latency;
454 if (current_routing == NULL && global_routing->root == NULL) {
456 /* it is the first one */
457 new_routing->routing_father = NULL;
458 global_routing->root = new_routing;
460 } else if (current_routing != NULL && global_routing->root != NULL) {
462 xbt_assert(!xbt_dict_get_or_null
463 (current_routing->routing_sons, AS_id),
464 "The AS \"%s\" already exists", AS_id);
465 /* it is a part of the tree */
466 new_routing->routing_father = current_routing;
467 /* set the father behavior */
468 if (current_routing->hierarchy == SURF_ROUTING_NULL)
469 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
470 /* add to the sons dictionary */
471 xbt_dict_set(current_routing->routing_sons, AS_id,
472 (void *) new_routing, NULL);
473 /* add to the father element list */
474 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
475 /* unload the prev parse rules */
476 (*(current_routing->routing->unload)) ();
479 THROWF(arg_error, 0, "All defined components must be belong to a AS");
481 /* set the new parse rules */
482 (*(new_routing->routing->load)) ();
483 /* set the new current component of the tree */
484 current_routing = new_routing;
488 * Detect the routing model type of the routing component from XML platforms
490 static void parse_S_AS(void)
492 routing_AS_init(A_surfxml_AS_id, A_surfxml_AS_routing);
497 * \brief Finish the creation of a new routing component
499 * When you finish to read the routing component, other structures must be created.
500 * the "end" method allow to do that for any routing model type
502 void routing_AS_end(const char *AS_id)
505 if (current_routing == NULL) {
506 THROWF(arg_error, 0, "Close AS(%s), that never open", AS_id);
508 network_element_info_t info = NULL;
509 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
510 "The AS \"%s\" already exists",current_routing->name);
511 info = xbt_new0(s_network_element_info_t, 1);
512 info->rc_component = current_routing->routing_father;
513 info->rc_type = SURF_NETWORK_ELEMENT_AS;
514 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
516 (*(current_routing->routing->unload)) ();
517 (*(current_routing->routing->end)) ();
518 current_routing = current_routing->routing_father;
519 if (current_routing != NULL)
520 (*(current_routing->routing->load)) ();
525 * \brief Finish the creation of a new routing component from XML
527 static void parse_E_AS_XML(void)
529 routing_AS_end(A_surfxml_AS_id);
532 /* Aux Business methods */
535 * \brief Get the AS name of the element
537 * \param name the host name
540 static char* elements_As_name(const char *name)
542 routing_component_t as_comp;
544 /* (1) find the as where the host is located */
545 as_comp = ((network_element_info_t)
546 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
547 return as_comp->name;
552 * \brief Get the AS father and the first elements of the chain
554 * \param src the source host name
555 * \param dst the destination host name
557 * Get the common father of the to processing units, and the first different
558 * father in the chain
560 static void elements_father(const char *src, const char *dst,
561 routing_component_t *res_father,
562 routing_component_t *res_src,
563 routing_component_t *res_dst)
565 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
566 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
567 routing_component_t src_as, dst_as;
568 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
569 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
572 routing_component_t current;
573 routing_component_t current_src;
574 routing_component_t current_dst;
575 routing_component_t father;
577 /* (1) find the as where the src and dst are located */
578 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
580 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
583 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
585 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
586 src_as = src_data->rc_component;
587 dst_as = dst_data->rc_component;
589 xbt_assert(src_as && dst_as,
590 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
592 /* (2) find the path to the root routing component */
593 for (current = src_as ; current != NULL ; current = current->routing_father) {
594 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
595 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
596 path_src[index_src++] = current;
598 for (current = dst_as ; current != NULL ; current = current->routing_father) {
599 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
600 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
601 path_dst[index_dst++] = current;
604 /* (3) find the common father */
606 current_src = path_src[--index_src];
607 current_dst = path_dst[--index_dst];
608 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
610 /* (4) they are not in the same routing component, make the path */
611 if (current_src == current_dst)
612 father = current_src;
614 father = path_src[index_src + 1];
616 /* (5) result generation */
617 *res_father = father; /* first the common father of src and dst */
618 *res_src = current_src; /* second the first different father of src */
619 *res_dst = current_dst; /* three the first different father of dst */
621 #undef ELEMENTS_FATHER_MAXDEPTH
624 /* Global Business methods */
627 * \brief Recursive function for get_route_latency
629 * \param src the source host name
630 * \param dst the destination host name
631 * \param *e_route the route where the links are stored
632 * \param *latency the latency, if needed
634 * This function is called by "get_route" and "get_latency". It allows to walk
635 * recursively through the routing components tree.
637 static void _get_route_latency(const char *src, const char *dst,
638 xbt_dynar_t *route, double *latency)
640 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
641 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
643 routing_component_t common_father;
644 routing_component_t src_father;
645 routing_component_t dst_father;
646 elements_father(src, dst, &common_father, &src_father, &dst_father);
648 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
650 route_extended_t e_route = NULL;
652 e_route = common_father->get_route(common_father, src, dst);
653 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
654 *route = e_route->generic_route.link_list;
657 *latency = common_father->get_latency(common_father, src, dst, e_route);
658 xbt_assert(*latency >= 0.0,
659 "latency error on route between \"%s\" and \"%s\"", src, dst);
662 xbt_free(e_route->src_gateway);
663 xbt_free(e_route->dst_gateway);
667 } else { /* SURF_ROUTING_RECURSIVE */
669 route_extended_t e_route_bypass = NULL;
670 if (common_father->get_bypass_route)
671 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
673 xbt_assert(!latency || !e_route_bypass,
674 "Bypass cannot work yet with get_latency");
676 route_extended_t e_route_cnt = e_route_bypass
678 : common_father->get_route(common_father,
679 src_father->name, dst_father->name);
681 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
682 src_father->name, dst_father->name);
684 xbt_assert((e_route_cnt->src_gateway == NULL) ==
685 (e_route_cnt->dst_gateway == NULL),
686 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
689 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
692 *latency = common_father->get_latency(common_father,
693 src_father->name, dst_father->name,
695 xbt_assert(*latency >= 0.0,
696 "latency error on route between \"%s\" and \"%s\"",
697 src_father->name, dst_father->name);
703 if (strcmp(src, e_route_cnt->src_gateway)) {
705 xbt_dynar_t route_src;
707 _get_route_latency(src, e_route_cnt->src_gateway,
708 (route ? &route_src : NULL),
709 (latency ? &latency_src : NULL));
711 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
712 src, e_route_cnt->src_gateway);
713 xbt_dynar_foreach(route_src, cpt, link) {
714 xbt_dynar_push(*route, &link);
716 xbt_dynar_free(&route_src);
719 xbt_assert(latency_src >= 0.0,
720 "latency error on route between \"%s\" and \"%s\"",
721 src, e_route_cnt->src_gateway);
722 *latency += latency_src;
727 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
728 xbt_dynar_push(*route, &link);
732 if (strcmp(e_route_cnt->dst_gateway, dst)) {
734 xbt_dynar_t route_dst;
736 _get_route_latency(e_route_cnt->dst_gateway, dst,
737 (route ? &route_dst : NULL),
738 (latency ? &latency_dst : NULL));
740 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
741 e_route_cnt->dst_gateway, dst);
742 xbt_dynar_foreach(route_dst, cpt, link) {
743 xbt_dynar_push(*route, &link);
745 xbt_dynar_free(&route_dst);
748 xbt_assert(latency_dst >= 0.0,
749 "latency error on route between \"%s\" and \"%s\"",
750 e_route_cnt->dst_gateway, dst);
751 *latency += latency_dst;
755 generic_free_extended_route(e_route_cnt);
760 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
762 static void get_route_latency(const char *src, const char *dst,
763 xbt_dynar_t *route, double *latency, int cleanup)
765 _get_route_latency(src, dst, route, latency);
766 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
767 xbt_assert(!latency || *latency >= 0.0,
768 "latency error on route between \"%s\" and \"%s\"", src, dst);
770 xbt_dynar_free(&global_routing->last_route);
771 global_routing->last_route = cleanup ? *route : NULL;
776 * \brief Generic method: find a route between hosts
778 * \param src the source host name
779 * \param dst the destination host name
781 * walk through the routing components tree and find a route between hosts
782 * by calling the differents "get_route" functions in each routing component.
783 * No need to free the returned dynar. It will be freed at the next call.
785 static xbt_dynar_t get_route(const char *src, const char *dst)
787 xbt_dynar_t route = NULL;
788 get_route_latency(src, dst, &route, NULL, 1);
793 * \brief Generic method: find a route between hosts
795 * \param src the source host name
796 * \param dst the destination host name
798 * same as get_route, but return NULL if any exception is raised.
800 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
802 xbt_dynar_t route = NULL;
805 get_route_latency(src, dst, &route, NULL, 1);
807 xbt_ex_free(exception);
814 * \brief Generic method: find a route between hosts
816 * \param src the source host name
817 * \param dst the destination host name
819 * walk through the routing components tree and find a route between hosts
820 * by calling the differents "get_route" functions in each routing component.
821 * Leaves the caller the responsability to clean the returned dynar.
823 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
825 xbt_dynar_t route = NULL;
826 get_route_latency(src, dst, &route, NULL, 0);
831 static double get_latency(const char *src, const char *dst)
833 double latency = -1.0;
834 get_route_latency(src, dst, NULL, &latency, 0);
839 * \brief Recursive function for finalize
841 * \param rc the source host name
843 * This fuction is call by "finalize". It allow to finalize the
844 * AS or routing components. It delete all the structures.
846 static void _finalize(routing_component_t rc)
849 xbt_dict_cursor_t cursor = NULL;
851 routing_component_t elem;
852 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
855 xbt_dict_t tmp_sons = rc->routing_sons;
856 char *tmp_name = rc->name;
857 xbt_dict_free(&tmp_sons);
859 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
860 current_routing->name);
861 (*(rc->finalize)) (rc);
866 * \brief Generic method: delete all the routing structures
868 * walk through the routing components tree and delete the structures
869 * by calling the differents "finalize" functions in each routing component
871 static void finalize(void)
873 /* delete recursibly all the tree */
874 _finalize(global_routing->root);
875 /* delete last_route */
876 xbt_dynar_free(&(global_routing->last_route));
877 /* delete global routing structure */
878 xbt_free(global_routing);
881 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
883 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
885 //adding my one link routes
888 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
890 xbt_dynar_foreach(onelink_mine, cpt, link) {
891 xbt_dynar_push(ret, &link);
896 xbt_dict_cursor_t cursor = NULL;
897 routing_component_t rc_child;
898 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
899 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
901 xbt_dynar_foreach(onelink_child, cpt, link) {
902 xbt_dynar_push(ret, &link);
909 static xbt_dynar_t get_onelink_routes(void)
911 return recursive_get_onelink_routes(global_routing->root);
914 e_surf_network_element_type_t get_network_element_type(const char
917 network_element_info_t rc = NULL;
919 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
920 if(rc) return rc->rc_type;
922 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
923 if(rc) return rc->rc_type;
925 return SURF_NETWORK_ELEMENT_NULL;
929 * \brief Generic method: create the global routing schema
931 * Make a global routing structure and set all the parsing functions.
933 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
935 /* config the uniq global routing */
936 global_routing = xbt_new0(s_routing_global_t, 1);
937 global_routing->root = NULL;
938 global_routing->get_route = get_route;
939 global_routing->get_route_or_null = get_route_or_null;
940 global_routing->get_latency = get_latency;
941 global_routing->get_route_no_cleanup = get_route_no_cleanup;
942 global_routing->get_onelink_routes = get_onelink_routes;
943 global_routing->get_route_latency = get_route_latency;
944 global_routing->get_network_element_type = get_network_element_type;
945 global_routing->finalize = finalize;
946 global_routing->loopback = loopback;
947 global_routing->size_of_link = size_of_links;
948 global_routing->last_route = NULL;
949 get_link_latency = get_link_latency_fun;
950 /* no current routing at moment */
951 current_routing = NULL;
953 /* parse generic elements */
954 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
955 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
956 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
958 surfxml_add_callback(STag_surfxml_route_cb_list,
959 &parse_S_route_new_and_endpoints_XML);
960 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
961 &parse_S_ASroute_new_and_endpoints);
962 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
963 &parse_S_bypassRoute_new_and_endpoints);
965 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
966 &parse_E_link_ctn_new_elem_XML);
968 surfxml_add_callback(ETag_surfxml_route_cb_list,
969 &parse_E_route_store_route);
970 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
971 &parse_E_ASroute_store_route);
972 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
973 &parse_E_bypassRoute_store_route);
975 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS);
976 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
978 surfxml_add_callback(STag_surfxml_cluster_cb_list,
979 &routing_parse_Scluster);
981 surfxml_add_callback(STag_surfxml_peer_cb_list,
982 &routing_parse_Speer);
984 surfxml_add_callback(ETag_surfxml_platform_cb_list,
988 instr_routing_define_callbacks();
992 void surf_parse_add_callback_config(void)
994 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
995 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
996 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
997 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
998 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1001 void surf_parse_models_setup()
1003 routing_parse_Erandom();
1004 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1005 surf_config_models_setup(platform_filename);
1006 free(platform_filename);
1009 /* ************************************************** */
1010 /* ********** PATERN FOR NEW ROUTING **************** */
1012 /* The minimal configuration of a new routing model need the next functions,
1013 * also you need to set at the start of the file, the new model in the model
1014 * list. Remember keep the null ending of the list.
1016 /*** Routing model structure ***/
1018 // s_routing_component_t generic_routing;
1019 // /* things that your routing model need */
1020 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1022 /*** Parse routing model functions ***/
1023 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1024 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1025 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1026 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1027 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1029 /*** Business methods ***/
1030 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1031 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1032 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1034 /*** Creation routing model functions ***/
1035 // static void* model_NEW_create(void) {
1036 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1037 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1038 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1039 // new_component->generic_routing.set_route = model_NEW_set_route;
1040 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1041 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1042 // new_component->generic_routing.get_route = NEW_get_route;
1043 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1044 // new_component->generic_routing.finalize = NEW_finalize;
1045 // /* initialization of internal structures */
1046 // return new_component;
1047 // } /* mandatory */
1048 // static void model_NEW_load(void) {} /* mandatory */
1049 // static void model_NEW_unload(void) {} /* mandatory */
1050 // static void model_NEW_end(void) {} /* mandatory */
1052 /* ************************************************************************** */
1053 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1055 void generic_set_processing_unit(routing_component_t rc,
1058 XBT_DEBUG("Load process unit \"%s\"", name);
1059 int *id = xbt_new0(int, 1);
1060 xbt_dict_t _to_index;
1061 _to_index = current_routing->to_index;
1062 *id = xbt_dict_length(_to_index);
1063 xbt_dict_set(_to_index, name, id, xbt_free);
1066 void generic_set_autonomous_system(routing_component_t rc,
1069 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1070 int *id = xbt_new0(int, 1);
1071 xbt_dict_t _to_index;
1072 _to_index = current_routing->to_index;
1073 *id = xbt_dict_length(_to_index);
1074 xbt_dict_set(_to_index, name, id, xbt_free);
1077 int surf_pointer_resource_cmp(const void *a, const void *b)
1082 int surf_link_resource_cmp(const void *a, const void *b)
1084 return !!memcmp(a,b,global_routing->size_of_link);
1087 void generic_set_bypassroute(routing_component_t rc,
1088 const char *src, const char *dst,
1089 route_extended_t e_route)
1091 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1092 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1095 route_name = bprintf("%s#%s", src, dst);
1096 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1097 "Invalid count of links, must be greater than zero (%s,%s)",
1099 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1100 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1101 src, e_route->src_gateway, dst, e_route->dst_gateway);
1103 route_extended_t new_e_route =
1104 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1105 xbt_dynar_free(&(e_route->generic_route.link_list));
1108 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1109 (void (*)(void *)) generic_free_extended_route);
1110 xbt_free(route_name);
1113 /* ************************************************************************** */
1114 /* *********************** GENERIC BUSINESS METHODS ************************* */
1116 double generic_get_link_latency(routing_component_t rc,
1117 const char *src, const char *dst,
1118 route_extended_t route)
1120 int need_to_clean = route?0:1;
1123 double latency = 0.0;
1125 route = route?route:rc->get_route(rc,src,dst);
1127 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1128 latency += get_link_latency(link);
1130 if(need_to_clean) generic_free_extended_route(route);
1134 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1136 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1139 route_extended_t generic_get_bypassroute(routing_component_t rc,
1143 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1144 routing_component_t src_as, dst_as;
1145 int index_src, index_dst;
1146 xbt_dynar_t path_src = NULL;
1147 xbt_dynar_t path_dst = NULL;
1148 routing_component_t current = NULL;
1149 routing_component_t *current_src = NULL;
1150 routing_component_t *current_dst = NULL;
1152 /* (1) find the as where the src and dst are located */
1153 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1154 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1155 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1156 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1158 if(src_data == NULL || dst_data == NULL)
1159 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1160 src, dst, rc->name);
1162 src_as = ((network_element_info_t)src_data)->rc_component;
1163 dst_as = ((network_element_info_t)dst_data)->rc_component;
1165 /* (2) find the path to the root routing component */
1166 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1168 while (current != NULL) {
1169 xbt_dynar_push(path_src, ¤t);
1170 current = current->routing_father;
1172 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1174 while (current != NULL) {
1175 xbt_dynar_push(path_dst, ¤t);
1176 current = current->routing_father;
1179 /* (3) find the common father */
1180 index_src = path_src->used - 1;
1181 index_dst = path_dst->used - 1;
1182 current_src = xbt_dynar_get_ptr(path_src, index_src);
1183 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1184 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1185 xbt_dynar_pop_ptr(path_src);
1186 xbt_dynar_pop_ptr(path_dst);
1189 current_src = xbt_dynar_get_ptr(path_src, index_src);
1190 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1193 int max_index_src = path_src->used - 1;
1194 int max_index_dst = path_dst->used - 1;
1196 int max_index = max(max_index_src, max_index_dst);
1199 route_extended_t e_route_bypass = NULL;
1201 for (max = 0; max <= max_index; max++) {
1202 for (i = 0; i < max; i++) {
1203 if (i <= max_index_src && max <= max_index_dst) {
1204 char *route_name = bprintf("%s#%s",
1205 (*(routing_component_t *)
1207 (path_src, i)))->name,
1208 (*(routing_component_t *)
1210 (path_dst, max)))->name);
1212 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1213 xbt_free(route_name);
1217 if (max <= max_index_src && i <= max_index_dst) {
1218 char *route_name = bprintf("%s#%s",
1219 (*(routing_component_t *)
1221 (path_src, max)))->name,
1222 (*(routing_component_t *)
1224 (path_dst, i)))->name);
1226 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1227 xbt_free(route_name);
1236 if (max <= max_index_src && max <= max_index_dst) {
1237 char *route_name = bprintf("%s#%s",
1238 (*(routing_component_t *)
1240 (path_src, max)))->name,
1241 (*(routing_component_t *)
1243 (path_dst, max)))->name);
1244 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1245 xbt_free(route_name);
1251 xbt_dynar_free(&path_src);
1252 xbt_dynar_free(&path_dst);
1254 route_extended_t new_e_route = NULL;
1256 if (e_route_bypass) {
1258 unsigned int cpt = 0;
1259 new_e_route = xbt_new0(s_route_extended_t, 1);
1260 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1261 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1262 new_e_route->generic_route.link_list =
1263 xbt_dynar_new(global_routing->size_of_link, NULL);
1264 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1265 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1272 /* ************************************************************************** */
1273 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1276 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1277 void *data, int order)
1283 xbt_dynar_t links = NULL, links_id = NULL;
1285 new_route = xbt_new0(s_route_t, 1);
1286 new_route->link_list =
1287 xbt_dynar_new(global_routing->size_of_link, NULL);
1289 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1290 "the hierarchy type is not SURF_ROUTING_BASE");
1292 links = ((route_t) data)->link_list;
1295 links_id = new_route->link_list;
1297 xbt_dynar_foreach(links, cpt, link_name) {
1300 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1303 xbt_dynar_push(links_id, &link);
1305 xbt_dynar_unshift(links_id, &link);
1307 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1314 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1315 void *data, int order)
1319 route_extended_t e_route, new_e_route;
1322 xbt_dynar_t links = NULL, links_id = NULL;
1324 new_e_route = xbt_new0(s_route_extended_t, 1);
1325 new_e_route->generic_route.link_list =
1326 xbt_dynar_new(global_routing->size_of_link, NULL);
1327 new_e_route->src_gateway = NULL;
1328 new_e_route->dst_gateway = NULL;
1330 xbt_assert(hierarchy == SURF_ROUTING_BASE
1331 || hierarchy == SURF_ROUTING_RECURSIVE,
1332 "the hierarchy type is not defined");
1334 if (hierarchy == SURF_ROUTING_BASE) {
1336 route = (route_t) data;
1337 links = route->link_list;
1339 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1341 e_route = (route_extended_t) data;
1342 xbt_assert(e_route->src_gateway
1343 && e_route->dst_gateway, "bad gateway, is null");
1344 links = e_route->generic_route.link_list;
1346 /* remeber not erase the gateway names */
1347 new_e_route->src_gateway = strdup(e_route->src_gateway);
1348 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1351 links_id = new_e_route->generic_route.link_list;
1353 xbt_dynar_foreach(links, cpt, link_name) {
1356 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1359 xbt_dynar_push(links_id, &link);
1361 xbt_dynar_unshift(links_id, &link);
1363 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1369 void generic_free_route(route_t route)
1372 xbt_dynar_free(&(route->link_list));
1377 void generic_free_extended_route(route_extended_t e_route)
1380 xbt_dynar_free(&(e_route->generic_route.link_list));
1381 if (e_route->src_gateway)
1382 xbt_free(e_route->src_gateway);
1383 if (e_route->dst_gateway)
1384 xbt_free(e_route->dst_gateway);
1389 static routing_component_t generic_as_exist(routing_component_t find_from,
1390 routing_component_t to_find)
1392 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1393 xbt_dict_cursor_t cursor = NULL;
1396 routing_component_t elem;
1397 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1398 if (to_find == elem || generic_as_exist(elem, to_find)) {
1409 generic_autonomous_system_exist(routing_component_t rc, char *element)
1411 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1412 routing_component_t element_as, result, elem;
1413 xbt_dict_cursor_t cursor = NULL;
1415 element_as = ((network_element_info_t)
1416 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1417 result = ((routing_component_t) - 1);
1418 if (element_as != rc)
1419 result = generic_as_exist(rc, element_as);
1423 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1424 found = !strcmp(elem->name, element);
1435 generic_processing_units_exist(routing_component_t rc, char *element)
1437 routing_component_t element_as;
1438 element_as = ((network_element_info_t)
1439 xbt_lib_get_or_null(host_lib,
1440 element, ROUTING_HOST_LEVEL))->rc_component;
1441 if (element_as == rc)
1443 return generic_as_exist(rc, element_as);
1446 void generic_src_dst_check(routing_component_t rc, const char *src,
1450 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1451 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1452 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1453 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1455 if(src_data == NULL || dst_data == NULL)
1456 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1457 src, dst, rc->name);
1459 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1460 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1462 if(src_as != dst_as)
1463 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1464 src, src_as->name, dst, dst_as->name);
1466 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1467 src,dst,src_as->name, dst_as->name,rc->name);
1470 static void routing_parse_Sconfig(void)
1472 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1475 static void routing_parse_Econfig(void)
1477 xbt_dict_cursor_t cursor = NULL;
1481 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1482 cfg = bprintf("%s:%s",key,elem);
1483 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1484 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1486 XBT_INFO("The custom configuration '%s' is already define by user!",key);
1489 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1492 void routing_parse_Scluster(void)
1494 static int AX_ptr = 0;
1495 char *host_id, *groups, *link_id = NULL;
1496 char *availability_file = xbt_strdup(A_surfxml_cluster_availability_file);
1497 char *state_file = xbt_strdup(A_surfxml_cluster_state_file);
1499 if(xbt_dict_size(patterns)==0)
1500 patterns = xbt_dict_new();
1502 xbt_dict_set(patterns,"id",struct_cluster->V_cluster_id,NULL);
1503 xbt_dict_set(patterns,"prefix",struct_cluster->V_cluster_prefix,NULL);
1504 xbt_dict_set(patterns,"suffix",struct_cluster->V_cluster_suffix,NULL);
1506 char *route_src_dst;
1509 xbt_dynar_t radical_elements;
1510 xbt_dynar_t radical_ends;
1511 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
1512 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
1514 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1515 static unsigned int surfxml_buffer_stack_stack[1024];
1517 surfxml_buffer_stack_stack[0] = 0;
1519 surfxml_bufferstack_push(1);
1521 SURFXML_BUFFER_SET(AS_id, struct_cluster->V_cluster_id);
1522 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
1523 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", struct_cluster->V_cluster_id);
1524 SURFXML_START_TAG(AS);
1526 radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ",");
1527 xbt_dynar_foreach(radical_elements, iter, groups) {
1528 radical_ends = xbt_str_split(groups, "-");
1529 switch (xbt_dynar_length(radical_ends)) {
1531 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
1532 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, start, struct_cluster->V_cluster_suffix);
1533 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start);
1534 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1535 A_surfxml_host_state = A_surfxml_host_state_ON;
1537 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, struct_cluster->S_cluster_power);
1538 SURFXML_BUFFER_SET(host_id, host_id);
1539 SURFXML_BUFFER_SET(host_power, struct_cluster->S_cluster_power);
1541 if(!strcmp(A_surfxml_cluster_availability_file,"")){
1542 char* tmp_availability_file = xbt_strdup(availability_file);
1543 xbt_str_varsubst(tmp_availability_file,patterns);
1544 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1545 SURFXML_BUFFER_SET(host_availability_file, tmp_availability_file);
1546 xbt_free(tmp_availability_file);
1550 XBT_DEBUG("\tavailability_file=\"\"");
1551 SURFXML_BUFFER_SET(host_availability_file, "");
1553 if(!strcmp(A_surfxml_cluster_state_file,"")){
1554 char *tmp_state_file = xbt_strdup(state_file);
1555 xbt_str_varsubst(tmp_state_file,patterns);
1556 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1557 SURFXML_BUFFER_SET(host_state_file, tmp_state_file);
1558 xbt_free(tmp_state_file);
1562 XBT_DEBUG("\tstate_file=\"\"");
1563 SURFXML_BUFFER_SET(host_state_file, "");
1566 SURFXML_BUFFER_SET(host_core, struct_cluster->S_cluster_core);
1567 SURFXML_BUFFER_SET(host_availability, "1.0");
1568 SURFXML_BUFFER_SET(host_coordinates, "");
1569 SURFXML_START_TAG(host);
1570 SURFXML_END_TAG(host);
1571 XBT_DEBUG("</host>");
1573 A_surfxml_link_state = A_surfxml_link_state_ON;
1574 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1575 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1576 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1577 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1578 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1580 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1582 SURFXML_BUFFER_SET(link_id, link_id);
1583 SURFXML_BUFFER_SET(link_bandwidth, struct_cluster->S_cluster_bw);
1584 SURFXML_BUFFER_SET(link_latency, struct_cluster->S_cluster_lat);
1585 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1586 SURFXML_BUFFER_SET(link_latency_file, "");
1587 SURFXML_BUFFER_SET(link_state_file, "");
1588 SURFXML_START_TAG(link);
1589 SURFXML_END_TAG(link);
1597 surf_parse_get_int(&start,
1598 xbt_dynar_get_as(radical_ends, 0, char *));
1599 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1600 for (i = start; i <= end; i++) {
1601 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1602 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1603 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1604 A_surfxml_host_state = A_surfxml_host_state_ON;
1606 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, struct_cluster->S_cluster_power);
1607 SURFXML_BUFFER_SET(host_id, host_id);
1608 SURFXML_BUFFER_SET(host_power, struct_cluster->S_cluster_power);
1610 if(!strcmp(A_surfxml_cluster_availability_file,"")){
1611 char* tmp_availability_file = xbt_strdup(availability_file);
1612 xbt_str_varsubst(tmp_availability_file,patterns);
1613 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1614 SURFXML_BUFFER_SET(host_availability_file, tmp_availability_file);
1615 xbt_free(tmp_availability_file);
1619 XBT_DEBUG("\tavailability_file=\"\"");
1620 SURFXML_BUFFER_SET(host_availability_file, "");
1622 if(!strcmp(A_surfxml_cluster_state_file,"")){
1623 char *tmp_state_file = xbt_strdup(state_file);
1624 xbt_str_varsubst(tmp_state_file,patterns);
1625 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1626 SURFXML_BUFFER_SET(host_state_file, tmp_state_file);
1627 xbt_free(tmp_state_file);
1631 XBT_DEBUG("\tstate_file=\"\"");
1632 SURFXML_BUFFER_SET(host_state_file, "");
1635 SURFXML_BUFFER_SET(host_core, struct_cluster->S_cluster_core);
1636 SURFXML_BUFFER_SET(host_availability, "1.0");
1637 SURFXML_BUFFER_SET(host_coordinates, "");
1638 SURFXML_START_TAG(host);
1639 SURFXML_END_TAG(host);
1640 XBT_DEBUG("</host>");
1642 A_surfxml_link_state = A_surfxml_link_state_ON;
1643 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1644 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1645 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1646 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1647 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1649 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1651 SURFXML_BUFFER_SET(link_id, link_id);
1652 SURFXML_BUFFER_SET(link_bandwidth, struct_cluster->S_cluster_bw);
1653 SURFXML_BUFFER_SET(link_latency, struct_cluster->S_cluster_lat);
1654 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1655 SURFXML_BUFFER_SET(link_latency_file, "");
1656 SURFXML_BUFFER_SET(link_state_file, "");
1657 SURFXML_START_TAG(link);
1658 SURFXML_END_TAG(link);
1666 XBT_DEBUG("Malformed radical");
1670 xbt_dynar_free(&radical_ends);
1672 xbt_dynar_free(&radical_elements);
1675 XBT_DEBUG("<router id=\"%s\"/>", struct_cluster->S_cluster_router_id);
1676 SURFXML_BUFFER_SET(router_id, struct_cluster->S_cluster_router_id);
1677 SURFXML_BUFFER_SET(router_coordinates, "");
1678 SURFXML_START_TAG(router);
1679 SURFXML_END_TAG(router);
1681 if( strcmp(struct_cluster->S_cluster_bb_bw,"") && strcmp(struct_cluster->S_cluster_bb_lat,"") ){
1682 char *link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1683 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,struct_cluster->S_cluster_bb_bw, struct_cluster->S_cluster_bb_lat);
1684 A_surfxml_link_state = A_surfxml_link_state_ON;
1685 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1686 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1687 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1688 SURFXML_BUFFER_SET(link_id, link_backbone);
1689 SURFXML_BUFFER_SET(link_bandwidth, struct_cluster->S_cluster_bb_bw);
1690 SURFXML_BUFFER_SET(link_latency, struct_cluster->S_cluster_bb_lat);
1691 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1692 SURFXML_BUFFER_SET(link_latency_file, "");
1693 SURFXML_BUFFER_SET(link_state_file, "");
1694 SURFXML_START_TAG(link);
1695 SURFXML_END_TAG(link);
1696 free(link_backbone);
1701 char *new_suffix = xbt_strdup("");
1703 radical_elements = xbt_str_split(struct_cluster->V_cluster_suffix, ".");
1704 xbt_dynar_foreach(radical_elements, iter, groups) {
1705 if (strcmp(groups, "")) {
1706 char *old_suffix = new_suffix;
1707 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1711 route_src_dst = bprintf("%s(.*)%s", struct_cluster->V_cluster_prefix, new_suffix);
1712 xbt_dynar_free(&radical_elements);
1713 xbt_free(new_suffix);
1715 char *pcre_link_src = bprintf("%s_link_$1src", struct_cluster->V_cluster_id);
1716 char *pcre_link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1717 char *pcre_link_dst = bprintf("%s_link_$1dst", struct_cluster->V_cluster_id);
1719 //from router to router
1720 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", struct_cluster->S_cluster_router_id, struct_cluster->S_cluster_router_id);
1721 XBT_DEBUG("symmetrical=\"NO\">");
1722 SURFXML_BUFFER_SET(route_src, struct_cluster->S_cluster_router_id);
1723 SURFXML_BUFFER_SET(route_dst, struct_cluster->S_cluster_router_id);
1724 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1725 SURFXML_START_TAG(route);
1727 if( strcmp(struct_cluster->S_cluster_bb_bw,"") && strcmp(struct_cluster->S_cluster_bb_lat,"") ){
1728 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1729 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1730 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1731 SURFXML_START_TAG(link_ctn);
1732 SURFXML_END_TAG(link_ctn);
1735 XBT_DEBUG("</route>");
1736 SURFXML_END_TAG(route);
1738 //from host to router
1739 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, struct_cluster->S_cluster_router_id);
1740 XBT_DEBUG("symmetrical=\"NO\">");
1741 SURFXML_BUFFER_SET(route_src, route_src_dst);
1742 SURFXML_BUFFER_SET(route_dst, struct_cluster->S_cluster_router_id);
1743 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1744 SURFXML_START_TAG(route);
1746 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1747 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1748 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1749 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1750 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1751 SURFXML_START_TAG(link_ctn);
1752 SURFXML_END_TAG(link_ctn);
1754 if( strcmp(struct_cluster->S_cluster_bb_bw,"") && strcmp(struct_cluster->S_cluster_bb_lat,"") ){
1755 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1756 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1757 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1758 SURFXML_START_TAG(link_ctn);
1759 SURFXML_END_TAG(link_ctn);
1762 XBT_DEBUG("</route>");
1763 SURFXML_END_TAG(route);
1765 //from router to host
1766 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", struct_cluster->S_cluster_router_id, route_src_dst);
1767 XBT_DEBUG("symmetrical=\"NO\">");
1768 SURFXML_BUFFER_SET(route_src, struct_cluster->S_cluster_router_id);
1769 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1770 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1771 SURFXML_START_TAG(route);
1773 if( strcmp(struct_cluster->S_cluster_bb_bw,"") && strcmp(struct_cluster->S_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("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1782 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1783 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1784 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1785 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1786 SURFXML_START_TAG(link_ctn);
1787 SURFXML_END_TAG(link_ctn);
1789 XBT_DEBUG("</route>");
1790 SURFXML_END_TAG(route);
1793 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
1794 XBT_DEBUG("symmetrical=\"NO\">");
1795 SURFXML_BUFFER_SET(route_src, route_src_dst);
1796 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1797 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1798 SURFXML_START_TAG(route);
1800 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1801 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
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 if( strcmp(struct_cluster->S_cluster_bb_bw,"") && strcmp(struct_cluster->S_cluster_bb_lat,"") ){
1809 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1810 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1811 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1812 SURFXML_START_TAG(link_ctn);
1813 SURFXML_END_TAG(link_ctn);
1816 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1817 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1818 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1819 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1820 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1821 SURFXML_START_TAG(link_ctn);
1822 SURFXML_END_TAG(link_ctn);
1824 XBT_DEBUG("</route>");
1825 SURFXML_END_TAG(route);
1827 free(pcre_link_dst);
1828 free(pcre_link_backbone);
1829 free(pcre_link_src);
1830 free(route_src_dst);
1832 xbt_free(availability_file);
1833 xbt_free(state_file);
1835 xbt_dict_free(&patterns);
1838 SURFXML_END_TAG(AS);
1841 surfxml_bufferstack_pop(1);
1844 * This function take a string and replace parameters from patterns dict.
1845 * It returns the new value.
1847 static char* replace_random_parameter(char * string)
1849 char *test_string = NULL;
1851 if(xbt_dict_size(random_value)==0)
1854 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1855 test_string = bprintf("${%s}", string);
1856 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1858 if (strcmp(test_string,"")) { //if not empty, keep this value.
1860 string = test_string;
1861 } //In other case take old value (without ${})
1867 static void clean_dict_random(void)
1869 xbt_dict_free(&random_value);
1870 xbt_dict_free(&patterns);
1873 static void routing_parse_Speer(void)
1875 static int AX_ptr = 0;
1876 char *host_id = NULL;
1877 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1879 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1880 static unsigned int surfxml_buffer_stack_stack[1024];
1882 surfxml_buffer_stack_stack[0] = 0;
1884 surfxml_bufferstack_push(1);
1886 SURFXML_BUFFER_SET(AS_id, struct_peer->V_peer_id);
1888 SURFXML_BUFFER_SET(AS_routing, "Full");
1889 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->V_peer_id);
1891 SURFXML_START_TAG(AS);
1894 host_id = bprintf("peer_%s", struct_peer->V_peer_id);
1895 router_id = bprintf("router_%s", struct_peer->V_peer_id);
1896 link_id_up = bprintf("link_%s_up", struct_peer->V_peer_id);
1897 link_id_down = bprintf("link_%s_down", struct_peer->V_peer_id);
1899 link_router = bprintf("%s_link_router", struct_peer->V_peer_id);
1900 link_backbone = bprintf("%s_backbone", struct_peer->V_peer_id);
1902 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, struct_peer->V_peer_power);
1903 A_surfxml_host_state = A_surfxml_host_state_ON;
1904 SURFXML_BUFFER_SET(host_id, host_id);
1905 SURFXML_BUFFER_SET(host_power, struct_peer->V_peer_power);
1906 SURFXML_BUFFER_SET(host_availability, "1.0");
1907 SURFXML_BUFFER_SET(host_availability_file, struct_peer->V_peer_availability_trace);
1908 SURFXML_BUFFER_SET(host_state_file, struct_peer->V_peer_state_trace);
1909 SURFXML_BUFFER_SET(host_coordinates, "");
1910 SURFXML_BUFFER_SET(host_core, "1.0");
1911 SURFXML_START_TAG(host);
1912 SURFXML_END_TAG(host);
1914 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->V_peer_coord);
1915 SURFXML_BUFFER_SET(router_id, router_id);
1916 SURFXML_BUFFER_SET(router_coordinates, struct_peer->V_peer_coord);
1917 SURFXML_START_TAG(router);
1918 SURFXML_END_TAG(router);
1920 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, struct_peer->V_peer_bw_in, struct_peer->V_peer_lat);
1921 A_surfxml_link_state = A_surfxml_link_state_ON;
1922 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1923 SURFXML_BUFFER_SET(link_id, link_id_up);
1924 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_in);
1925 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1926 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1927 SURFXML_BUFFER_SET(link_latency_file, "");
1928 SURFXML_BUFFER_SET(link_state_file, "");
1929 SURFXML_START_TAG(link);
1930 SURFXML_END_TAG(link);
1932 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, struct_peer->V_peer_bw_out, struct_peer->V_peer_lat);
1933 A_surfxml_link_state = A_surfxml_link_state_ON;
1934 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1935 SURFXML_BUFFER_SET(link_id, link_id_down);
1936 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_out);
1937 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1938 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1939 SURFXML_BUFFER_SET(link_latency_file, "");
1940 SURFXML_BUFFER_SET(link_state_file, "");
1941 SURFXML_START_TAG(link);
1942 SURFXML_END_TAG(link);
1947 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1948 XBT_DEBUG("symmetrical=\"NO\">");
1949 SURFXML_BUFFER_SET(route_src, host_id);
1950 SURFXML_BUFFER_SET(route_dst, router_id);
1951 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1952 SURFXML_START_TAG(route);
1954 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1955 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1956 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1957 SURFXML_START_TAG(link_ctn);
1958 SURFXML_END_TAG(link_ctn);
1960 XBT_DEBUG("</route>");
1961 SURFXML_END_TAG(route);
1964 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1965 XBT_DEBUG("symmetrical=\"NO\">");
1966 SURFXML_BUFFER_SET(route_src, router_id);
1967 SURFXML_BUFFER_SET(route_dst, host_id);
1968 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1969 SURFXML_START_TAG(route);
1971 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
1972 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
1973 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1974 SURFXML_START_TAG(link_ctn);
1975 SURFXML_END_TAG(link_ctn);
1977 XBT_DEBUG("</route>");
1978 SURFXML_END_TAG(route);
1981 SURFXML_END_TAG(AS);
1984 //xbt_dynar_free(&tab_elements_num);
1988 free(link_backbone);
1991 surfxml_bufferstack_pop(1);
1994 static void routing_parse_Srandom(void)
1996 double mean, std, min, max, seed;
1997 char *random_id = A_surfxml_random_id;
1998 char *random_radical = A_surfxml_random_radical;
1999 char *rd_name = NULL;
2001 surf_parse_get_double(&mean,A_surfxml_random_mean);
2002 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2003 surf_parse_get_double(&min,A_surfxml_random_min);
2004 surf_parse_get_double(&max,A_surfxml_random_max);
2005 surf_parse_get_double(&seed,A_surfxml_random_seed);
2009 random_data_t random = xbt_new0(s_random_data_t, 1);
2012 xbt_dynar_t radical_elements;
2016 xbt_dynar_t radical_ends;
2018 random->generator = A_surfxml_random_generator;
2019 random->seed = seed;
2023 /* Check user stupidities */
2025 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2027 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2030 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2033 /* normalize the mean and standard deviation before storing */
2034 random->mean = (mean - min) / (max - min);
2035 random->std = std / (max - min);
2037 if (random->mean * (1 - random->mean) < random->std * random->std)
2038 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2039 random->mean, random->std);
2041 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2051 if(xbt_dict_size(random_value)==0)
2052 random_value = xbt_dict_new();
2054 if(!strcmp(random_radical,""))
2056 res = random_generate(random);
2057 rd_value = bprintf("%f",res);
2058 xbt_dict_set(random_value, random_id, rd_value, free);
2062 radical_elements = xbt_str_split(random_radical, ",");
2063 xbt_dynar_foreach(radical_elements, iter, groups) {
2064 radical_ends = xbt_str_split(groups, "-");
2065 switch (xbt_dynar_length(radical_ends)) {
2067 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2068 res = random_generate(random);
2069 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2070 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2074 case 2: surf_parse_get_int(&start,
2075 xbt_dynar_get_as(radical_ends, 0, char *));
2076 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2077 for (i = start; i <= end; i++) {
2078 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2079 res = random_generate(random);
2080 tmpbuf = bprintf("%s%d",random_id,i);
2081 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2086 XBT_INFO("Malformed radical");
2089 res = random_generate(random);
2090 rd_name = bprintf("%s_router",random_id);
2091 rd_value = bprintf("%f",res);
2092 xbt_dict_set(random_value, rd_name, rd_value, free);
2094 xbt_dynar_free(&radical_ends);
2097 xbt_dynar_free(&radical_elements);
2101 static void routing_parse_Erandom(void)
2103 xbt_dict_cursor_t cursor = NULL;
2107 xbt_dict_foreach(random_value, cursor, key, elem) {
2108 XBT_DEBUG("%s = %s",key,elem);
2115 * New methods to init the routing model component from the lua script
2120 * add a host to the network element list
2123 void routing_add_host(const char *host_id)
2125 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2129 * Set a new link on the actual list of link for a route or ASroute
2131 void routing_add_link(const char *link_id)
2133 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2137 *Set the endpoints for a route
2139 void routing_set_route(const char *src_id, const char *dst_id)
2141 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2145 * Store the route by calling parse_E_route_store_route
2147 void routing_store_route(void)
2149 parse_E_route_store_route();