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"
12 static xbt_dict_t patterns = NULL;
13 static xbt_dict_t random_value = NULL;
16 routing_global_t global_routing = NULL;
17 routing_component_t current_routing = NULL;
18 model_type_t current_routing_model = NULL;
20 /* global parse functions */
21 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
22 static const char *src = NULL; /* temporary store the source name of a route */
23 static const char *dst = NULL; /* temporary store the destination name of a route */
24 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
25 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
26 static double_f_cpvoid_t get_link_latency = NULL;
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
30 static void routing_parse_Speer(void); /* peer bypass */
31 static void routing_parse_Srandom(void); /* random bypass */
32 static void routing_parse_Erandom(void); /* random bypass */
34 static void routing_parse_Sconfig(void); /* config Tag */
35 static void routing_parse_Econfig(void); /* config Tag */
37 static char* replace_random_parameter(char * chaine);
38 static void clean_dict_random(void);
40 /* this lines are only for replace use like index in the model table */
45 SURF_MODEL_DIJKSTRACACHE,
52 struct s_model_type routing_models[] = { {"Full",
53 "Full routing data (fast, large memory requirements, fully expressive)",
59 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
60 model_floyd_create, model_floyd_load, model_floyd_unload,
63 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
64 model_dijkstra_create, model_dijkstra_both_load,
65 model_dijkstra_both_unload, model_dijkstra_both_end},
67 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
68 model_dijkstracache_create, model_dijkstra_both_load,
69 model_dijkstra_both_unload, model_dijkstra_both_end},
70 {"none", "No routing (usable with Constant network only)",
71 model_none_create, model_none_load, model_none_unload, model_none_end},
73 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
74 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
75 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
76 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
78 {NULL, NULL, NULL, NULL, NULL, NULL}
81 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
83 double src_coord, dst_coord;
85 src_coord = atof(xbt_dynar_get_as(src, index, char *));
86 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
88 return (src_coord-dst_coord)*(src_coord-dst_coord);
92 static double base_vivaldi_get_latency (const char *src, const char *dst)
94 double euclidean_dist;
95 xbt_dynar_t src_ctn, dst_ctn;
96 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
97 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
98 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
99 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
101 if(dst_ctn == NULL || src_ctn == NULL)
102 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
104 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
105 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
107 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
109 return euclidean_dist;
112 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
114 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
115 int need_to_clean = e_route?0:1;
117 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
118 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
119 if(need_to_clean) generic_free_extended_route(e_route);
122 return base_vivaldi_get_latency(src,dst);
127 * \brief Add a "host" to the network element list
129 static void parse_S_host(const char *host_id, const char* coord)
131 network_element_info_t info = NULL;
132 if (current_routing->hierarchy == SURF_ROUTING_NULL)
133 current_routing->hierarchy = SURF_ROUTING_BASE;
134 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
135 "Reading a host, processing unit \"%s\" already exists",
137 xbt_assert(current_routing->set_processing_unit,
138 "no defined method \"set_processing_unit\" in \"%s\"",
139 current_routing->name);
140 (*(current_routing->set_processing_unit)) (current_routing, host_id);
141 info = xbt_new0(s_network_element_info_t, 1);
142 info->rc_component = current_routing;
143 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
144 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
145 if (strcmp(coord,"")) {
146 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
147 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
148 xbt_dynar_shrink(ctn, 0);
149 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
153 static void parse_E_host(void)
155 xbt_dict_cursor_t cursor = NULL;
159 xbt_dict_foreach(current_property_set, cursor, key, elem) {
160 XBT_DEBUG("property : %s = %s",key,elem);
165 * \brief Add a host to the network element list from XML
167 static void parse_S_host_XML(void)
169 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
171 static void parse_E_host_XML(void)
177 * \brief Add a host to the network element list from lua script
179 static void parse_S_host_lua(const char *host_id, const char *coord)
181 parse_S_host(host_id, coord);
186 * \brief Add a "router" to the network element list
188 static void parse_S_router(const char *router_id)
190 network_element_info_t info = NULL;
192 if (current_routing->hierarchy == SURF_ROUTING_NULL)
193 current_routing->hierarchy = SURF_ROUTING_BASE;
194 xbt_assert(!xbt_lib_get_or_null(as_router_lib,A_surfxml_router_id, ROUTING_ASR_LEVEL),
195 "Reading a router, processing unit \"%s\" already exists",
197 xbt_assert(current_routing->set_processing_unit,
198 "no defined method \"set_processing_unit\" in \"%s\"",
199 current_routing->name);
200 (*(current_routing->set_processing_unit)) (current_routing,
202 info = xbt_new0(s_network_element_info_t, 1);
203 info->rc_component = current_routing;
204 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
206 xbt_lib_set(as_router_lib,router_id,ROUTING_ASR_LEVEL,(void *) info);
207 if (strcmp(A_surfxml_router_coordinates,"")) {
208 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
209 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
210 xbt_dynar_shrink(ctn, 0);
211 xbt_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn);
216 * brief Add a "router" to the network element list from XML description
218 static void parse_S_router_XML(void)
220 return parse_S_router(A_surfxml_router_id);
224 * brief Add a "router" to the network element list from XML description
226 static void parse_S_router_lua(const char* router_id)
228 return parse_S_router(router_id);
232 * \brief Set the endponints for a route
234 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
236 if (src != NULL && dst != NULL && link_list != NULL)
237 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
241 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
242 "Some limits are null in the route between \"%s\" and \"%s\"",
244 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
248 * \brief Set the endpoints for a route from XML
250 static void parse_S_route_new_and_endpoints_XML(void)
252 parse_S_route_new_and_endpoints(A_surfxml_route_src,
253 A_surfxml_route_dst);
257 * \brief Set the endpoints for a route from lua
259 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
261 parse_S_route_new_and_endpoints(id_src, id_dst);
265 * \brief Set the endponints and gateways for a ASroute
267 static void parse_S_ASroute_new_and_endpoints(void)
269 if (src != NULL && dst != NULL && link_list != NULL)
270 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
271 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
272 src = A_surfxml_ASroute_src;
273 dst = A_surfxml_ASroute_dst;
274 gw_src = A_surfxml_ASroute_gw_src;
275 gw_dst = A_surfxml_ASroute_gw_dst;
276 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
277 || strlen(gw_dst) > 0,
278 "Some limits are null in the route between \"%s\" and \"%s\"",
280 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
284 * \brief Set the endponints for a bypassRoute
286 static void parse_S_bypassRoute_new_and_endpoints(void)
288 if (src != NULL && dst != NULL && link_list != NULL)
290 "Bypass Route between %s to %s can not be defined",
291 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
292 src = A_surfxml_bypassRoute_src;
293 dst = A_surfxml_bypassRoute_dst;
294 gw_src = A_surfxml_bypassRoute_gw_src;
295 gw_dst = A_surfxml_bypassRoute_gw_dst;
296 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
297 || strlen(gw_dst) > 0,
298 "Some limits are null in the route between \"%s\" and \"%s\"",
300 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
304 * \brief Set a new link on the actual list of link for a route or ASroute
306 static void parse_E_link_ctn_new_elem(const char *link_id)
309 val = xbt_strdup(link_id);
310 xbt_dynar_push(link_list, &val);
314 * \brief Set a new link on the actual list of link for a route or ASroute from XML
317 static void parse_E_link_ctn_new_elem_XML(void)
319 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
320 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
321 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
322 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
323 parse_E_link_ctn_new_elem(link_id);
326 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
327 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
328 parse_E_link_ctn_new_elem(link_id);
334 * \brief Set a new link on the actual list of link for a route or ASroute from lua
336 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
338 parse_E_link_ctn_new_elem(link_id);
342 * \brief Store the route by calling the set_route function of the current routing component
344 static void parse_E_route_store_route(void)
346 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
347 route->generic_route.link_list = link_list;
348 xbt_assert(current_routing->set_route,
349 "no defined method \"set_route\" in \"%s\"",
350 current_routing->name);
351 (*(current_routing->set_route)) (current_routing, src, dst, route);
358 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
360 static void parse_E_ASroute_store_route(void)
362 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
363 e_route->generic_route.link_list = link_list;
364 e_route->src_gateway = xbt_strdup(gw_src);
365 e_route->dst_gateway = xbt_strdup(gw_dst);
366 xbt_assert(current_routing->set_ASroute,
367 "no defined method \"set_ASroute\" in \"%s\"",
368 current_routing->name);
369 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
378 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
380 static void parse_E_bypassRoute_store_route(void)
382 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
383 e_route->generic_route.link_list = link_list;
384 e_route->src_gateway = xbt_strdup(gw_src);
385 e_route->dst_gateway = xbt_strdup(gw_dst);
386 xbt_assert(current_routing->set_bypassroute,
387 "no defined method \"set_bypassroute\" in \"%s\"",
388 current_routing->name);
389 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
399 * \brief Make a new routing component
401 * make the new structure and
402 * set the parsing functions to allows parsing the part of the routing tree
404 static void parse_S_AS(char *AS_id, char *AS_routing)
406 routing_component_t new_routing;
407 model_type_t model = NULL;
408 char *wanted = AS_routing;
410 /* seach the routing model */
411 for (cpt = 0; routing_models[cpt].name; cpt++)
412 if (!strcmp(wanted, routing_models[cpt].name))
413 model = &routing_models[cpt];
414 /* if its not exist, error */
416 fprintf(stderr, "Routing model %s not found. Existing models:\n",
418 for (cpt = 0; routing_models[cpt].name; cpt++)
419 if (!strcmp(wanted, routing_models[cpt].name))
420 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
421 routing_models[cpt].desc);
425 /* make a new routing component */
426 new_routing = (routing_component_t) (*(model->create)) ();
427 new_routing->routing = model;
428 new_routing->hierarchy = SURF_ROUTING_NULL;
429 new_routing->name = xbt_strdup(AS_id);
430 new_routing->routing_sons = xbt_dict_new();
432 /* Hack for Vivaldi */
433 if(!strcmp(model->name,"Vivaldi"))
434 new_routing->get_latency = vivaldi_get_link_latency;
436 if (current_routing == NULL && global_routing->root == NULL) {
438 /* it is the first one */
439 new_routing->routing_father = NULL;
440 global_routing->root = new_routing;
442 } else if (current_routing != NULL && global_routing->root != NULL) {
444 xbt_assert(!xbt_dict_get_or_null
445 (current_routing->routing_sons, AS_id),
446 "The AS \"%s\" already exists", AS_id);
447 /* it is a part of the tree */
448 new_routing->routing_father = current_routing;
449 /* set the father behavior */
450 if (current_routing->hierarchy == SURF_ROUTING_NULL)
451 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
452 /* add to the sons dictionary */
453 xbt_dict_set(current_routing->routing_sons, AS_id,
454 (void *) new_routing, NULL);
455 /* add to the father element list */
456 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
457 /* unload the prev parse rules */
458 (*(current_routing->routing->unload)) ();
461 THROWF(arg_error, 0, "All defined components must be belong to a AS");
463 /* set the new parse rules */
464 (*(new_routing->routing->load)) ();
465 /* set the new current component of the tree */
466 current_routing = new_routing;
470 * Detect the routing model type of the routing component from XML platforms
472 static void parse_S_AS_XML(void)
474 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
478 * define the routing model type of routing component from lua script
480 static void parse_S_AS_lua(char *id, char *mode)
482 parse_S_AS(id, mode);
487 * \brief Finish the creation of a new routing component
489 * When you finish to read the routing component, other structures must be created.
490 * the "end" method allow to do that for any routing model type
492 static void parse_E_AS(const char *AS_id)
495 if (current_routing == NULL) {
496 THROWF(arg_error, 0, "Close AS(%s), that never open", AS_id);
498 network_element_info_t info = NULL;
499 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
500 "The AS \"%s\" already exists",current_routing->name);
501 info = xbt_new0(s_network_element_info_t, 1);
502 info->rc_component = current_routing->routing_father;
503 info->rc_type = SURF_NETWORK_ELEMENT_AS;
504 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
506 (*(current_routing->routing->unload)) ();
507 (*(current_routing->routing->end)) ();
508 current_routing = current_routing->routing_father;
509 if (current_routing != NULL)
510 (*(current_routing->routing->load)) ();
515 * \brief Finish the creation of a new routing component from XML
517 static void parse_E_AS_XML(void)
519 parse_E_AS(A_surfxml_AS_id);
523 * \brief Finish the creation of a new routing component from lua
525 static void parse_E_AS_lua(const char *id)
530 /* Aux Business methods */
533 * \brief Get the AS name of the element
535 * \param name the host name
538 static char* elements_As_name(const char *name)
540 routing_component_t as_comp;
542 /* (1) find the as where the host is located */
543 as_comp = ((network_element_info_t)
544 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
545 return as_comp->name;
550 * \brief Get the AS father and the first elements of the chain
552 * \param src the source host name
553 * \param dst the destination host name
555 * Get the common father of the to processing units, and the first different
556 * father in the chain
558 static xbt_dynar_t elements_father(const char *src, const char *dst)
561 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
563 xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
565 routing_component_t src_as, dst_as;
566 int index_src, index_dst, index_father_src, index_father_dst;
567 xbt_dynar_t path_src = NULL;
568 xbt_dynar_t path_dst = NULL;
569 routing_component_t current = NULL;
570 routing_component_t *current_src = NULL;
571 routing_component_t *current_dst = NULL;
572 routing_component_t *father = NULL;
574 /* (1) find the as where the src and dst are located */
575 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
576 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
577 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
578 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
579 src_as = ((network_element_info_t)src_data)->rc_component;
580 dst_as = ((network_element_info_t)dst_data)->rc_component;
584 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
587 /* (2) find the path to the root routing component */
588 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
590 while (current != NULL) {
591 xbt_dynar_push(path_src, ¤t);
592 current = current->routing_father;
594 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
596 while (current != NULL) {
597 xbt_dynar_push(path_dst, ¤t);
598 current = current->routing_father;
601 /* (3) find the common father */
602 index_src = path_src->used - 1;
603 index_dst = path_dst->used - 1;
604 current_src = xbt_dynar_get_ptr(path_src, index_src);
605 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
606 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
607 current_src = xbt_dynar_get_ptr(path_src, index_src);
608 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
614 current_src = xbt_dynar_get_ptr(path_src, index_src);
615 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
617 /* (4) they are not in the same routing component, make the path */
618 index_father_src = index_src + 1;
619 index_father_dst = index_dst + 1;
621 if (*current_src == *current_dst)
622 father = current_src;
624 father = xbt_dynar_get_ptr(path_src, index_father_src);
626 /* (5) result generation */
627 xbt_dynar_push(result, father); /* first same the father of src and dst */
628 xbt_dynar_push(result, current_src); /* second the first different father of src */
629 xbt_dynar_push(result, current_dst); /* three the first different father of dst */
631 xbt_dynar_free(&path_src);
632 xbt_dynar_free(&path_dst);
637 /* Global Business methods */
640 * \brief Recursive function for get_route
642 * \param src the source host name
643 * \param dst the destination host name
645 * This function is called by "get_route". It allows to walk recursively
646 * through the routing components tree.
648 static route_extended_t _get_route(const char *src, const char *dst)
652 unsigned int cpt = 0;
654 XBT_DEBUG("Solve route \"%s\" to \"%s\"", src, dst);
656 xbt_assert(src && dst, "bad parameters for \"_get_route\" method");
658 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
661 xbt_dynar_t elem_father_list = elements_father(src, dst);
663 routing_component_t common_father =
664 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
665 routing_component_t src_father =
666 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
667 routing_component_t dst_father =
668 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
670 e_route = xbt_new0(s_route_extended_t, 1);
671 e_route->src_gateway = NULL;
672 e_route->dst_gateway = NULL;
673 e_route->generic_route.link_list =
674 xbt_dynar_new(global_routing->size_of_link, NULL);
676 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
679 (*(common_father->get_route)) (common_father, src, dst);
680 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
682 // FIXME (optim): faire une copie et pas une série de push
683 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
684 xbt_dynar_push(e_route->generic_route.link_list, &link);
686 generic_free_extended_route(e_route_cnt);
688 } else { /* SURF_ROUTING_RECURSIVE */
690 route_extended_t e_route_bypass = NULL;
692 if (common_father->get_bypass_route)
694 (*(common_father->get_bypass_route)) (common_father, src, dst);
697 e_route_cnt = e_route_bypass;
700 (*(common_father->get_route)) (common_father, src_father->name,
703 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
704 src_father->name, dst_father->name);
706 xbt_assert((e_route_cnt->src_gateway == NULL) ==
707 (e_route_cnt->dst_gateway == NULL),
708 "bad gateway for route between \"%s\" and \"%s\"", src,
711 if (strcmp(src, e_route_cnt->src_gateway)) {
712 e_route_src = _get_route(src, e_route_cnt->src_gateway);
713 xbt_assert(e_route_src, "no route between \"%s\" and \"%s\"", src,
714 e_route_cnt->src_gateway);
715 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
716 xbt_dynar_push(e_route->generic_route.link_list, &link);
720 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
721 xbt_dynar_push(e_route->generic_route.link_list, &link);
724 if (strcmp(e_route_cnt->dst_gateway, dst)) {
725 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
726 xbt_assert(e_route_dst, "no route between \"%s\" and \"%s\"",
727 e_route_cnt->dst_gateway, dst);
728 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
729 xbt_dynar_push(e_route->generic_route.link_list, &link);
733 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
734 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
736 generic_free_extended_route(e_route_src);
737 generic_free_extended_route(e_route_cnt);
738 generic_free_extended_route(e_route_dst);
741 xbt_dynar_free(&elem_father_list);
746 static double _get_latency(const char *src, const char *dst)
748 double latency, latency_src, latency_dst = 0.0;
750 XBT_DEBUG("Solve route \"%s\" to \"%s\"", src, dst);
751 xbt_assert(src && dst, "bad parameters for \"_get_route\" method");
753 route_extended_t e_route_cnt;
755 xbt_dynar_t elem_father_list = elements_father(src, dst);
757 routing_component_t common_father =
758 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
759 routing_component_t src_father =
760 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
761 routing_component_t dst_father =
762 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
764 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
767 (*(common_father->get_latency)) (common_father, src, dst, NULL);
768 xbt_assert(latency>=0, "no route between \"%s\" and \"%s\"", src,
771 } else { /* SURF_ROUTING_RECURSIVE */
772 route_extended_t e_route_bypass = NULL;
773 if (common_father->get_bypass_route)
775 (*(common_father->get_bypass_route)) (common_father, src, dst);
777 xbt_assert(!e_route_bypass,"Bypass cannot work yet with get_latency");
780 (*(common_father->get_route)) (common_father, src_father->name,
783 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
784 src_father->name, dst_father->name);
786 xbt_assert((e_route_cnt->src_gateway == NULL) ==
787 (e_route_cnt->dst_gateway == NULL),
788 "bad gateway for route between \"%s\" and \"%s\"", src,
791 latency = (*(common_father->get_latency)) (common_father, src_father->name, dst_father->name, e_route_cnt);
793 xbt_assert(latency>=0, "no route between \"%s\" and \"%s\"",
794 src_father->name, dst_father->name);
796 if (strcmp(src,e_route_cnt->src_gateway)) {
798 latency_src = _get_latency(src, e_route_cnt->src_gateway);
799 xbt_assert(latency_src>=0, "no route between \"%s\" and \"%s\"", src,
800 e_route_cnt->src_gateway);
801 latency += latency_src;
804 if (strcmp(e_route_cnt->dst_gateway,dst)) {
806 latency_dst = _get_latency(e_route_cnt->dst_gateway, dst);
807 xbt_assert(latency_dst>=0, "no route between \"%s\" and \"%s\"",
808 e_route_cnt->dst_gateway, dst);
809 latency += latency_dst;
814 xbt_dynar_free(&elem_father_list);
820 * \brief Generic method: find a route between hosts
822 * \param src the source host name
823 * \param dst the destination host name
825 * walk through the routing components tree and find a route between hosts
826 * by calling the differents "get_route" functions in each routing component.
827 * No need to free the returned dynar. It will be freed at the next call.
829 static xbt_dynar_t get_route(const char *src, const char *dst)
832 route_extended_t e_route;
834 e_route = _get_route(src, dst);
835 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
837 if (global_routing->last_route)
838 xbt_dynar_free(&(global_routing->last_route));
839 global_routing->last_route = e_route->generic_route.link_list;
841 if (e_route->src_gateway)
842 xbt_free(e_route->src_gateway);
843 if (e_route->dst_gateway)
844 xbt_free(e_route->dst_gateway);
848 return global_routing->last_route;
852 * \brief Generic method: find a route between hosts
854 * \param src the source host name
855 * \param dst the destination host name
857 * walk through the routing components tree and find a route between hosts
858 * by calling the differents "get_route" functions in each routing component.
859 * Leaves the caller the responsability to clean the returned dynar.
861 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
863 xbt_dynar_t d = get_route(src,dst);
864 global_routing->last_route = NULL;
869 static double get_latency(const char *src, const char *dst)
872 double latency = -1.0;
873 latency = _get_latency(src, dst);
874 xbt_assert(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst);
879 * \brief Recursive function for finalize
881 * \param rc the source host name
883 * This fuction is call by "finalize". It allow to finalize the
884 * AS or routing components. It delete all the structures.
886 static void _finalize(routing_component_t rc)
889 xbt_dict_cursor_t cursor = NULL;
891 routing_component_t elem;
892 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
895 xbt_dict_t tmp_sons = rc->routing_sons;
896 char *tmp_name = rc->name;
897 xbt_dict_free(&tmp_sons);
899 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
900 current_routing->name);
901 (*(rc->finalize)) (rc);
906 * \brief Generic method: delete all the routing structures
908 * walk through the routing components tree and delete the structures
909 * by calling the differents "finalize" functions in each routing component
911 static void finalize(void)
913 /* delete recursibly all the tree */
914 _finalize(global_routing->root);
915 /* delete last_route */
916 xbt_dynar_free(&(global_routing->last_route));
917 /* delete global routing structure */
918 xbt_free(global_routing);
921 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
923 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
925 //adding my one link routes
928 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
930 xbt_dynar_foreach(onelink_mine, cpt, link) {
931 xbt_dynar_push(ret, &link);
936 xbt_dict_cursor_t cursor = NULL;
937 routing_component_t rc_child;
938 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
939 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
941 xbt_dynar_foreach(onelink_child, cpt, link) {
942 xbt_dynar_push(ret, &link);
949 static xbt_dynar_t get_onelink_routes(void)
951 return recursive_get_onelink_routes(global_routing->root);
954 e_surf_network_element_type_t get_network_element_type(const char
957 network_element_info_t rc = NULL;
959 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
960 if(rc) return rc->rc_type;
962 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
963 if(rc) return rc->rc_type;
965 return SURF_NETWORK_ELEMENT_NULL;
969 * \brief Generic method: create the global routing schema
971 * Make a global routing structure and set all the parsing functions.
973 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
975 /* config the uniq global routing */
976 global_routing = xbt_new0(s_routing_global_t, 1);
977 global_routing->root = NULL;
978 global_routing->get_route = get_route;
979 global_routing->get_latency = get_latency;
980 global_routing->get_route_no_cleanup = get_route_no_cleanup;
981 global_routing->get_onelink_routes = get_onelink_routes;
982 global_routing->get_network_element_type = get_network_element_type;
983 global_routing->finalize = finalize;
984 global_routing->loopback = loopback;
985 global_routing->size_of_link = size_of_links;
986 global_routing->last_route = NULL;
987 get_link_latency = get_link_latency_fun;
988 /* no current routing at moment */
989 current_routing = NULL;
991 /* parse generic elements */
992 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
993 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
994 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
996 surfxml_add_callback(STag_surfxml_route_cb_list,
997 &parse_S_route_new_and_endpoints_XML);
998 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
999 &parse_S_ASroute_new_and_endpoints);
1000 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
1001 &parse_S_bypassRoute_new_and_endpoints);
1003 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
1004 &parse_E_link_ctn_new_elem_XML);
1006 surfxml_add_callback(ETag_surfxml_route_cb_list,
1007 &parse_E_route_store_route);
1008 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
1009 &parse_E_ASroute_store_route);
1010 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
1011 &parse_E_bypassRoute_store_route);
1013 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
1014 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
1016 surfxml_add_callback(STag_surfxml_cluster_cb_list,
1017 &routing_parse_Scluster);
1019 surfxml_add_callback(STag_surfxml_peer_cb_list,
1020 &routing_parse_Speer);
1022 surfxml_add_callback(ETag_surfxml_platform_cb_list,
1023 &clean_dict_random);
1026 instr_routing_define_callbacks();
1030 void surf_parse_add_callback_config(void)
1032 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1033 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1034 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1035 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
1036 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1039 void surf_parse_models_setup()
1041 routing_parse_Erandom();
1042 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1043 surf_config_models_setup(platform_filename);
1044 free(platform_filename);
1047 /* ************************************************** */
1048 /* ********** PATERN FOR NEW ROUTING **************** */
1050 /* The minimal configuration of a new routing model need the next functions,
1051 * also you need to set at the start of the file, the new model in the model
1052 * list. Remember keep the null ending of the list.
1054 /*** Routing model structure ***/
1056 // s_routing_component_t generic_routing;
1057 // /* things that your routing model need */
1058 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1060 /*** Parse routing model functions ***/
1061 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1062 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1063 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1064 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1065 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1067 /*** Business methods ***/
1068 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1069 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1070 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1072 /*** Creation routing model functions ***/
1073 // static void* model_NEW_create(void) {
1074 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1075 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1076 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1077 // new_component->generic_routing.set_route = model_NEW_set_route;
1078 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1079 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1080 // new_component->generic_routing.get_route = NEW_get_route;
1081 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1082 // new_component->generic_routing.finalize = NEW_finalize;
1083 // /* initialization of internal structures */
1084 // return new_component;
1085 // } /* mandatory */
1086 // static void model_NEW_load(void) {} /* mandatory */
1087 // static void model_NEW_unload(void) {} /* mandatory */
1088 // static void model_NEW_end(void) {} /* mandatory */
1090 /* ************************************************************************** */
1091 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1093 void generic_set_processing_unit(routing_component_t rc,
1096 XBT_DEBUG("Load process unit \"%s\"", name);
1097 int *id = xbt_new0(int, 1);
1098 xbt_dict_t _to_index;
1099 _to_index = current_routing->to_index;
1100 *id = xbt_dict_length(_to_index);
1101 xbt_dict_set(_to_index, name, id, xbt_free);
1104 void generic_set_autonomous_system(routing_component_t rc,
1107 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1108 int *id = xbt_new0(int, 1);
1109 xbt_dict_t _to_index;
1110 _to_index = current_routing->to_index;
1111 *id = xbt_dict_length(_to_index);
1112 xbt_dict_set(_to_index, name, id, xbt_free);
1115 int surf_pointer_resource_cmp(const void *a, const void *b)
1120 int surf_link_resource_cmp(const void *a, const void *b)
1122 return !!memcmp(a,b,global_routing->size_of_link);
1125 void generic_set_bypassroute(routing_component_t rc,
1126 const char *src, const char *dst,
1127 route_extended_t e_route)
1129 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1130 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1133 route_name = bprintf("%s#%s", src, dst);
1134 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1135 "Invalid count of links, must be greater than zero (%s,%s)",
1137 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1138 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1139 src, e_route->src_gateway, dst, e_route->dst_gateway);
1141 route_extended_t new_e_route =
1142 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1143 xbt_dynar_free(&(e_route->generic_route.link_list));
1146 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1147 (void (*)(void *)) generic_free_extended_route);
1148 xbt_free(route_name);
1151 /* ************************************************************************** */
1152 /* *********************** GENERIC BUSINESS METHODS ************************* */
1154 double generic_get_link_latency(routing_component_t rc,
1155 const char *src, const char *dst,
1156 route_extended_t route)
1158 int need_to_clean = route?0:1;
1161 double latency = 0.0;
1163 route = route?route:rc->get_route(rc,src,dst);
1165 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1166 latency += get_link_latency(link);
1168 if(need_to_clean) generic_free_extended_route(route);
1172 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1174 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1177 route_extended_t generic_get_bypassroute(routing_component_t rc,
1181 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1182 routing_component_t src_as, dst_as;
1183 int index_src, index_dst;
1184 xbt_dynar_t path_src = NULL;
1185 xbt_dynar_t path_dst = NULL;
1186 routing_component_t current = NULL;
1187 routing_component_t *current_src = NULL;
1188 routing_component_t *current_dst = NULL;
1190 /* (1) find the as where the src and dst are located */
1191 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1192 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1193 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1194 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1196 if(src_data == NULL || dst_data == NULL)
1197 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1198 src, dst, rc->name);
1200 src_as = ((network_element_info_t)src_data)->rc_component;
1201 dst_as = ((network_element_info_t)dst_data)->rc_component;
1203 /* (2) find the path to the root routing component */
1204 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1206 while (current != NULL) {
1207 xbt_dynar_push(path_src, ¤t);
1208 current = current->routing_father;
1210 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1212 while (current != NULL) {
1213 xbt_dynar_push(path_dst, ¤t);
1214 current = current->routing_father;
1217 /* (3) find the common father */
1218 index_src = path_src->used - 1;
1219 index_dst = path_dst->used - 1;
1220 current_src = xbt_dynar_get_ptr(path_src, index_src);
1221 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1222 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1223 routing_component_t *tmp_src, *tmp_dst;
1224 tmp_src = xbt_dynar_pop_ptr(path_src);
1225 tmp_dst = xbt_dynar_pop_ptr(path_dst);
1228 current_src = xbt_dynar_get_ptr(path_src, index_src);
1229 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1232 int max_index_src = path_src->used - 1;
1233 int max_index_dst = path_dst->used - 1;
1235 int max_index = max(max_index_src, max_index_dst);
1238 route_extended_t e_route_bypass = NULL;
1240 for (max = 0; max <= max_index; max++) {
1241 for (i = 0; i < max; i++) {
1242 if (i <= max_index_src && max <= max_index_dst) {
1243 char *route_name = bprintf("%s#%s",
1244 (*(routing_component_t *)
1246 (path_src, i)))->name,
1247 (*(routing_component_t *)
1249 (path_dst, max)))->name);
1251 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1252 xbt_free(route_name);
1256 if (max <= max_index_src && i <= max_index_dst) {
1257 char *route_name = bprintf("%s#%s",
1258 (*(routing_component_t *)
1260 (path_src, max)))->name,
1261 (*(routing_component_t *)
1263 (path_dst, i)))->name);
1265 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1266 xbt_free(route_name);
1275 if (max <= max_index_src && max <= max_index_dst) {
1276 char *route_name = bprintf("%s#%s",
1277 (*(routing_component_t *)
1279 (path_src, max)))->name,
1280 (*(routing_component_t *)
1282 (path_dst, max)))->name);
1283 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1284 xbt_free(route_name);
1290 xbt_dynar_free(&path_src);
1291 xbt_dynar_free(&path_dst);
1293 route_extended_t new_e_route = NULL;
1295 if (e_route_bypass) {
1297 unsigned int cpt = 0;
1298 new_e_route = xbt_new0(s_route_extended_t, 1);
1299 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1300 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1301 new_e_route->generic_route.link_list =
1302 xbt_dynar_new(global_routing->size_of_link, NULL);
1303 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1304 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1311 /* ************************************************************************** */
1312 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1315 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1316 void *data, int order)
1322 xbt_dynar_t links = NULL, links_id = NULL;
1324 new_route = xbt_new0(s_route_t, 1);
1325 new_route->link_list =
1326 xbt_dynar_new(global_routing->size_of_link, NULL);
1328 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1329 "the hierarchy type is not SURF_ROUTING_BASE");
1331 links = ((route_t) data)->link_list;
1334 links_id = new_route->link_list;
1336 xbt_dynar_foreach(links, cpt, link_name) {
1339 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1342 xbt_dynar_push(links_id, &link);
1344 xbt_dynar_unshift(links_id, &link);
1346 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1353 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1354 void *data, int order)
1358 route_extended_t e_route, new_e_route;
1361 xbt_dynar_t links = NULL, links_id = NULL;
1363 new_e_route = xbt_new0(s_route_extended_t, 1);
1364 new_e_route->generic_route.link_list =
1365 xbt_dynar_new(global_routing->size_of_link, NULL);
1366 new_e_route->src_gateway = NULL;
1367 new_e_route->dst_gateway = NULL;
1369 xbt_assert(hierarchy == SURF_ROUTING_BASE
1370 || hierarchy == SURF_ROUTING_RECURSIVE,
1371 "the hierarchy type is not defined");
1373 if (hierarchy == SURF_ROUTING_BASE) {
1375 route = (route_t) data;
1376 links = route->link_list;
1378 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1380 e_route = (route_extended_t) data;
1381 xbt_assert(e_route->src_gateway
1382 && e_route->dst_gateway, "bad gateway, is null");
1383 links = e_route->generic_route.link_list;
1385 /* remeber not erase the gateway names */
1386 new_e_route->src_gateway = strdup(e_route->src_gateway);
1387 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1390 links_id = new_e_route->generic_route.link_list;
1392 xbt_dynar_foreach(links, cpt, link_name) {
1395 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1398 xbt_dynar_push(links_id, &link);
1400 xbt_dynar_unshift(links_id, &link);
1402 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1408 void generic_free_route(route_t route)
1411 xbt_dynar_free(&(route->link_list));
1416 void generic_free_extended_route(route_extended_t e_route)
1419 xbt_dynar_free(&(e_route->generic_route.link_list));
1420 if (e_route->src_gateway)
1421 xbt_free(e_route->src_gateway);
1422 if (e_route->dst_gateway)
1423 xbt_free(e_route->dst_gateway);
1428 static routing_component_t generic_as_exist(routing_component_t find_from,
1429 routing_component_t to_find)
1431 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1432 xbt_dict_cursor_t cursor = NULL;
1435 routing_component_t elem;
1436 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1437 if (to_find == elem || generic_as_exist(elem, to_find)) {
1448 generic_autonomous_system_exist(routing_component_t rc, char *element)
1450 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1451 routing_component_t element_as, result, elem;
1452 xbt_dict_cursor_t cursor = NULL;
1454 element_as = ((network_element_info_t)
1455 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1456 result = ((routing_component_t) - 1);
1457 if (element_as != rc)
1458 result = generic_as_exist(rc, element_as);
1462 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1463 found = !strcmp(elem->name, element);
1474 generic_processing_units_exist(routing_component_t rc, char *element)
1476 routing_component_t element_as;
1477 element_as = ((network_element_info_t)
1478 xbt_lib_get_or_null(host_lib,
1479 element, ROUTING_HOST_LEVEL))->rc_component;
1480 if (element_as == rc)
1482 return generic_as_exist(rc, element_as);
1485 void generic_src_dst_check(routing_component_t rc, const char *src,
1489 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1490 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1491 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1492 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1494 if(src_data == NULL || dst_data == NULL)
1495 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1496 src, dst, rc->name);
1498 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1499 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1501 if(src_as != dst_as)
1502 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1503 src, src_as->name, dst, dst_as->name);
1505 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1506 src,dst,src_as->name, dst_as->name,rc->name);
1509 static void routing_parse_Sconfig(void)
1511 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1514 static void routing_parse_Econfig(void)
1516 xbt_dict_cursor_t cursor = NULL;
1520 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1521 cfg = bprintf("%s:%s",key,elem);
1522 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1523 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1525 XBT_INFO("The custom configuration '%s' is already define by user!",key);
1528 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1531 void routing_parse_Scluster(void)
1533 static int AX_ptr = 0;
1535 char *cluster_id = A_surfxml_cluster_id;
1536 char *cluster_prefix = A_surfxml_cluster_prefix;
1537 char *cluster_suffix = A_surfxml_cluster_suffix;
1538 char *cluster_radical = A_surfxml_cluster_radical;
1539 char *cluster_power = A_surfxml_cluster_power;
1540 char *cluster_core = A_surfxml_cluster_core;
1541 char *cluster_bw = A_surfxml_cluster_bw;
1542 char *cluster_lat = A_surfxml_cluster_lat;
1543 char *temp_cluster_bw = NULL;
1544 char *temp_cluster_lat = NULL;
1545 char *temp_cluster_power = NULL;
1546 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1547 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1548 char *cluster_availability_file = A_surfxml_cluster_availability_file;
1549 char *cluster_state_file = A_surfxml_cluster_state_file;
1550 char *host_id, *groups, *link_id = NULL;
1551 char *router_id, *link_backbone;
1552 char *availability_file = xbt_strdup(cluster_availability_file);
1553 char *state_file = xbt_strdup(cluster_state_file);
1555 if(xbt_dict_size(patterns)==0)
1556 patterns = xbt_dict_new();
1558 xbt_dict_set(patterns,"id",cluster_id,NULL);
1559 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
1560 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
1562 #ifdef HAVE_PCRE_LIB
1563 char *route_src_dst;
1567 xbt_dynar_t radical_elements;
1568 xbt_dynar_t radical_ends;
1569 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
1570 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
1572 #ifndef HAVE_PCRE_LIB
1573 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
1574 char *route_src, *route_dst;
1578 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1579 static unsigned int surfxml_buffer_stack_stack[1024];
1581 surfxml_buffer_stack_stack[0] = 0;
1583 surfxml_bufferstack_push(1);
1585 SURFXML_BUFFER_SET(AS_id, cluster_id);
1586 #ifdef HAVE_PCRE_LIB
1587 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
1588 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
1590 SURFXML_BUFFER_SET(AS_routing, "Full");
1591 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
1593 SURFXML_START_TAG(AS);
1595 radical_elements = xbt_str_split(cluster_radical, ",");
1596 xbt_dynar_foreach(radical_elements, iter, groups) {
1597 radical_ends = xbt_str_split(groups, "-");
1598 switch (xbt_dynar_length(radical_ends)) {
1600 surf_parse_get_int(&start,
1601 xbt_dynar_get_as(radical_ends, 0, char *));
1602 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
1603 #ifndef HAVE_PCRE_LIB
1604 xbt_dynar_push_as(tab_elements_num, int, start);
1606 link_id = bprintf("%s_link_%d", cluster_id, start);
1608 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1609 temp_cluster_power = xbt_strdup(cluster_power);
1610 temp_cluster_power = replace_random_parameter(temp_cluster_power);
1611 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1612 A_surfxml_host_state = A_surfxml_host_state_ON;
1613 SURFXML_BUFFER_SET(host_id, host_id);
1614 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1615 SURFXML_BUFFER_SET(host_core, cluster_core);
1616 SURFXML_BUFFER_SET(host_availability, "1.0");
1617 SURFXML_BUFFER_SET(host_coordinates, "");
1618 xbt_free(availability_file);
1619 availability_file = xbt_strdup(cluster_availability_file);
1620 xbt_free(state_file);
1621 state_file = xbt_strdup(cluster_state_file);
1622 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1623 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1624 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1625 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1626 XBT_DEBUG("</host>");
1627 SURFXML_START_TAG(host);
1628 SURFXML_END_TAG(host);
1631 temp_cluster_bw = xbt_strdup(cluster_bw);
1632 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1633 temp_cluster_lat = xbt_strdup(cluster_lat);
1634 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1635 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1636 A_surfxml_link_state = A_surfxml_link_state_ON;
1637 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1638 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1639 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1640 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1641 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1642 SURFXML_BUFFER_SET(link_id, link_id);
1643 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1644 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1645 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1646 SURFXML_BUFFER_SET(link_latency_file, "");
1647 SURFXML_BUFFER_SET(link_state_file, "");
1648 SURFXML_START_TAG(link);
1649 SURFXML_END_TAG(link);
1651 xbt_free(temp_cluster_bw);
1652 xbt_free(temp_cluster_lat);
1653 xbt_free(temp_cluster_power);
1660 surf_parse_get_int(&start,
1661 xbt_dynar_get_as(radical_ends, 0, char *));
1662 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1663 for (i = start; i <= end; i++) {
1664 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
1665 #ifndef HAVE_PCRE_LIB
1666 xbt_dynar_push_as(tab_elements_num, int, i);
1668 link_id = bprintf("%s_link_%d", cluster_id, i);
1670 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1671 temp_cluster_power = xbt_strdup(cluster_power);
1672 temp_cluster_power = replace_random_parameter(temp_cluster_power);
1673 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1674 A_surfxml_host_state = A_surfxml_host_state_ON;
1675 SURFXML_BUFFER_SET(host_id, host_id);
1676 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1677 SURFXML_BUFFER_SET(host_core, cluster_core);
1678 SURFXML_BUFFER_SET(host_availability, "1.0");
1679 SURFXML_BUFFER_SET(host_coordinates, "");
1680 xbt_free(availability_file);
1681 availability_file = xbt_strdup(cluster_availability_file);
1682 xbt_free(state_file);
1683 state_file = xbt_strdup(cluster_state_file);
1684 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1685 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1686 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1687 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1688 XBT_DEBUG("</host>");
1689 SURFXML_START_TAG(host);
1690 SURFXML_END_TAG(host);
1692 xbt_free(temp_cluster_power);
1694 temp_cluster_bw = xbt_strdup(cluster_bw);
1695 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1696 temp_cluster_lat = xbt_strdup(cluster_lat);
1697 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1698 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1699 A_surfxml_link_state = A_surfxml_link_state_ON;
1700 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1701 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1702 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1703 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1704 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1705 SURFXML_BUFFER_SET(link_id, link_id);
1706 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1707 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1708 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1709 SURFXML_BUFFER_SET(link_latency_file, "");
1710 SURFXML_BUFFER_SET(link_state_file, "");
1711 SURFXML_START_TAG(link);
1712 SURFXML_END_TAG(link);
1714 xbt_free(temp_cluster_bw);
1715 xbt_free(temp_cluster_lat);
1722 XBT_DEBUG("Malformed radical");
1725 xbt_dynar_free(&radical_ends);
1727 xbt_dynar_free(&radical_elements);
1731 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
1733 //link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
1734 link_backbone = bprintf("%s_backbone", cluster_id);
1736 XBT_DEBUG("<router id=\"%s\"/>", router_id);
1737 SURFXML_BUFFER_SET(router_id, router_id);
1738 SURFXML_BUFFER_SET(router_coordinates, "");
1739 SURFXML_START_TAG(router);
1740 SURFXML_END_TAG(router);
1743 // xbt_dict_set(patterns, "radical", xbt_strdup("_router"), xbt_free);
1744 // temp_cluster_bw = xbt_strdup(cluster_bw);
1745 // temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1746 // temp_cluster_lat = xbt_strdup(cluster_lat);
1747 // temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1748 // XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,temp_cluster_bw, temp_cluster_lat);
1749 // A_surfxml_link_state = A_surfxml_link_state_ON;
1750 // A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1751 // if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1752 // {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1753 // if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1754 // {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1755 // SURFXML_BUFFER_SET(link_id, link_router);
1756 // SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1757 // SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1758 // SURFXML_BUFFER_SET(link_bandwidth_file, "");
1759 // SURFXML_BUFFER_SET(link_latency_file, "");
1760 // SURFXML_BUFFER_SET(link_state_file, "");
1761 // SURFXML_START_TAG(link);
1762 // SURFXML_END_TAG(link);
1764 // xbt_free(temp_cluster_bw);
1765 // xbt_free(temp_cluster_lat);
1767 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
1768 A_surfxml_link_state = A_surfxml_link_state_ON;
1769 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1770 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1771 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1772 SURFXML_BUFFER_SET(link_id, link_backbone);
1773 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
1774 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
1775 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1776 SURFXML_BUFFER_SET(link_latency_file, "");
1777 SURFXML_BUFFER_SET(link_state_file, "");
1778 SURFXML_START_TAG(link);
1779 SURFXML_END_TAG(link);
1783 #ifdef HAVE_PCRE_LIB
1784 char *new_suffix = xbt_strdup("");
1786 radical_elements = xbt_str_split(cluster_suffix, ".");
1787 xbt_dynar_foreach(radical_elements, iter, groups) {
1788 if (strcmp(groups, "")) {
1789 char *old_suffix = new_suffix;
1790 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1794 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
1795 xbt_dynar_free(&radical_elements);
1798 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
1799 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
1800 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
1802 //from router to router
1803 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, router_id);
1804 XBT_DEBUG("symmetrical=\"NO\">");
1805 SURFXML_BUFFER_SET(route_src, router_id);
1806 SURFXML_BUFFER_SET(route_dst, router_id);
1807 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1808 SURFXML_START_TAG(route);
1810 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1811 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1812 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1813 SURFXML_START_TAG(link_ctn);
1814 SURFXML_END_TAG(link_ctn);
1816 XBT_DEBUG("</route>");
1817 SURFXML_END_TAG(route);
1819 //from host to router
1820 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, router_id);
1821 XBT_DEBUG("symmetrical=\"NO\">");
1822 SURFXML_BUFFER_SET(route_src, route_src_dst);
1823 SURFXML_BUFFER_SET(route_dst, router_id);
1824 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1825 SURFXML_START_TAG(route);
1827 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1828 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1829 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1830 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1831 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1832 SURFXML_START_TAG(link_ctn);
1833 SURFXML_END_TAG(link_ctn);
1835 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1836 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1837 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1838 SURFXML_START_TAG(link_ctn);
1839 SURFXML_END_TAG(link_ctn);
1841 XBT_DEBUG("</route>");
1842 SURFXML_END_TAG(route);
1844 //from router to host
1845 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, route_src_dst);
1846 XBT_DEBUG("symmetrical=\"NO\">");
1847 SURFXML_BUFFER_SET(route_src, router_id);
1848 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1849 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1850 SURFXML_START_TAG(route);
1852 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1853 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1854 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1855 SURFXML_START_TAG(link_ctn);
1856 SURFXML_END_TAG(link_ctn);
1858 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1859 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1860 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1861 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1862 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1863 SURFXML_START_TAG(link_ctn);
1864 SURFXML_END_TAG(link_ctn);
1866 XBT_DEBUG("</route>");
1867 SURFXML_END_TAG(route);
1870 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
1871 XBT_DEBUG("symmetrical=\"NO\">");
1872 SURFXML_BUFFER_SET(route_src, route_src_dst);
1873 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1874 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1875 SURFXML_START_TAG(route);
1877 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1878 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1879 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1880 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1881 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1882 SURFXML_START_TAG(link_ctn);
1883 SURFXML_END_TAG(link_ctn);
1885 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1886 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1887 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1888 SURFXML_START_TAG(link_ctn);
1889 SURFXML_END_TAG(link_ctn);
1891 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1892 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1893 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1894 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1895 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1896 SURFXML_START_TAG(link_ctn);
1897 SURFXML_END_TAG(link_ctn);
1899 XBT_DEBUG("</route>");
1900 SURFXML_END_TAG(route);
1902 free(pcre_link_dst);
1903 free(pcre_link_backbone);
1904 free(pcre_link_src);
1905 free(route_src_dst);
1907 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
1908 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
1909 if (i == xbt_dynar_length(tab_elements_num)) {
1910 route_src = router_id;
1913 bprintf("%s%d%s", cluster_prefix,
1914 xbt_dynar_get_as(tab_elements_num, i, int),
1918 if (j == xbt_dynar_length(tab_elements_num)) {
1919 route_dst = router_id;
1922 bprintf("%s%d%s", cluster_prefix,
1923 xbt_dynar_get_as(tab_elements_num, j, int),
1927 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
1928 XBT_DEBUG("symmetrical=\"NO\">");
1929 SURFXML_BUFFER_SET(route_src, route_src);
1930 SURFXML_BUFFER_SET(route_dst, route_dst);
1931 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1932 SURFXML_START_TAG(route);
1934 if (i != xbt_dynar_length(tab_elements_num)){
1936 bprintf("%s_link_%d", cluster_id,
1937 xbt_dynar_get_as(tab_elements_num, i, int));
1938 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_src);
1939 SURFXML_BUFFER_SET(link_ctn_id, route_src);
1940 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1941 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1942 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1943 SURFXML_START_TAG(link_ctn);
1944 SURFXML_END_TAG(link_ctn);
1948 XBT_DEBUG("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
1949 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
1950 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1951 SURFXML_START_TAG(link_ctn);
1952 SURFXML_END_TAG(link_ctn);
1954 if (j != xbt_dynar_length(tab_elements_num)) {
1956 bprintf("%s_link_%d", cluster_id,
1957 xbt_dynar_get_as(tab_elements_num, j, int));
1958 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_dst);
1959 SURFXML_BUFFER_SET(link_ctn_id, route_dst);
1960 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1961 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1962 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1963 SURFXML_START_TAG(link_ctn);
1964 SURFXML_END_TAG(link_ctn);
1968 XBT_DEBUG("</route>");
1969 SURFXML_END_TAG(route);
1972 xbt_dynar_free(&tab_elements_num);
1977 free(link_backbone);
1978 //free(link_router);
1979 xbt_dict_free(&patterns);
1980 free(availability_file);
1984 SURFXML_END_TAG(AS);
1987 surfxml_bufferstack_pop(1);
1990 * This function take a string and replace parameters from patterns dict.
1991 * It returns the new value.
1993 static char* replace_random_parameter(char * string)
1995 char *test_string = NULL;
1997 if(xbt_dict_size(random_value)==0)
2000 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
2001 test_string = bprintf("${%s}", string);
2002 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
2004 if (strcmp(test_string,"")) { //if not empty, keep this value.
2006 string = test_string;
2007 } //In other case take old value (without ${})
2013 static void clean_dict_random(void)
2015 xbt_dict_free(&random_value);
2016 xbt_dict_free(&patterns);
2019 static void routing_parse_Speer(void)
2021 static int AX_ptr = 0;
2023 char *peer_id = A_surfxml_peer_id;
2024 char *peer_power = A_surfxml_peer_power;
2025 char *peer_bw_in = A_surfxml_peer_bw_in;
2026 char *peer_bw_out = A_surfxml_peer_bw_out;
2027 char *peer_lat = A_surfxml_peer_lat;
2028 char *peer_coord = A_surfxml_peer_coordinates;
2029 char *peer_state_file = A_surfxml_peer_state_file;
2030 char *peer_availability_file = A_surfxml_peer_availability_file;
2032 char *host_id = NULL;
2033 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
2035 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
2036 static unsigned int surfxml_buffer_stack_stack[1024];
2038 surfxml_buffer_stack_stack[0] = 0;
2040 surfxml_bufferstack_push(1);
2042 SURFXML_BUFFER_SET(AS_id, peer_id);
2044 SURFXML_BUFFER_SET(AS_routing, "Full");
2045 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
2047 SURFXML_START_TAG(AS);
2050 host_id = bprintf("peer_%s", peer_id);
2051 router_id = bprintf("router_%s", peer_id);
2052 link_id_up = bprintf("link_%s_up", peer_id);
2053 link_id_down = bprintf("link_%s_down", peer_id);
2055 link_router = bprintf("%s_link_router", peer_id);
2056 link_backbone = bprintf("%s_backbone", peer_id);
2058 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
2059 A_surfxml_host_state = A_surfxml_host_state_ON;
2060 SURFXML_BUFFER_SET(host_id, host_id);
2061 SURFXML_BUFFER_SET(host_power, peer_power);
2062 SURFXML_BUFFER_SET(host_availability, "1.0");
2063 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
2064 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
2065 SURFXML_BUFFER_SET(host_coordinates, "");
2066 SURFXML_START_TAG(host);
2067 SURFXML_END_TAG(host);
2069 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
2070 SURFXML_BUFFER_SET(router_id, router_id);
2071 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
2072 SURFXML_START_TAG(router);
2073 SURFXML_END_TAG(router);
2075 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
2076 A_surfxml_link_state = A_surfxml_link_state_ON;
2077 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2078 SURFXML_BUFFER_SET(link_id, link_id_up);
2079 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
2080 SURFXML_BUFFER_SET(link_latency, peer_lat);
2081 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2082 SURFXML_BUFFER_SET(link_latency_file, "");
2083 SURFXML_BUFFER_SET(link_state_file, "");
2084 SURFXML_START_TAG(link);
2085 SURFXML_END_TAG(link);
2087 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
2088 A_surfxml_link_state = A_surfxml_link_state_ON;
2089 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2090 SURFXML_BUFFER_SET(link_id, link_id_down);
2091 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
2092 SURFXML_BUFFER_SET(link_latency, peer_lat);
2093 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2094 SURFXML_BUFFER_SET(link_latency_file, "");
2095 SURFXML_BUFFER_SET(link_state_file, "");
2096 SURFXML_START_TAG(link);
2097 SURFXML_END_TAG(link);
2102 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
2103 XBT_DEBUG("symmetrical=\"NO\">");
2104 SURFXML_BUFFER_SET(route_src, host_id);
2105 SURFXML_BUFFER_SET(route_dst, router_id);
2106 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2107 SURFXML_START_TAG(route);
2109 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
2110 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
2111 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2112 SURFXML_START_TAG(link_ctn);
2113 SURFXML_END_TAG(link_ctn);
2115 XBT_DEBUG("</route>");
2116 SURFXML_END_TAG(route);
2119 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
2120 XBT_DEBUG("symmetrical=\"NO\">");
2121 SURFXML_BUFFER_SET(route_src, router_id);
2122 SURFXML_BUFFER_SET(route_dst, host_id);
2123 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2124 SURFXML_START_TAG(route);
2126 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
2127 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
2128 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2129 SURFXML_START_TAG(link_ctn);
2130 SURFXML_END_TAG(link_ctn);
2132 XBT_DEBUG("</route>");
2133 SURFXML_END_TAG(route);
2136 SURFXML_END_TAG(AS);
2139 //xbt_dynar_free(&tab_elements_num);
2143 free(link_backbone);
2146 surfxml_bufferstack_pop(1);
2149 static void routing_parse_Srandom(void)
2151 double mean, std, min, max, seed;
2152 char *random_id = A_surfxml_random_id;
2153 char *random_radical = A_surfxml_random_radical;
2154 char *rd_name = NULL;
2156 surf_parse_get_double(&mean,A_surfxml_random_mean);
2157 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2158 surf_parse_get_double(&min,A_surfxml_random_min);
2159 surf_parse_get_double(&max,A_surfxml_random_max);
2160 surf_parse_get_double(&seed,A_surfxml_random_seed);
2164 random_data_t random = xbt_new0(s_random_data_t, 1);
2167 xbt_dynar_t radical_elements;
2171 xbt_dynar_t radical_ends;
2173 random->generator = A_surfxml_random_generator;
2174 random->seed = seed;
2178 /* Check user stupidities */
2180 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2182 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2185 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2188 /* normalize the mean and standard deviation before storing */
2189 random->mean = (mean - min) / (max - min);
2190 random->std = std / (max - min);
2192 if (random->mean * (1 - random->mean) < random->std * random->std)
2193 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2194 random->mean, random->std);
2196 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2206 if(xbt_dict_size(random_value)==0)
2207 random_value = xbt_dict_new();
2209 if(!strcmp(random_radical,""))
2211 res = random_generate(random);
2212 rd_value = bprintf("%f",res);
2213 xbt_dict_set(random_value, random_id, rd_value, free);
2217 radical_elements = xbt_str_split(random_radical, ",");
2218 xbt_dynar_foreach(radical_elements, iter, groups) {
2219 radical_ends = xbt_str_split(groups, "-");
2220 switch (xbt_dynar_length(radical_ends)) {
2222 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2223 res = random_generate(random);
2224 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2225 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2229 case 2: surf_parse_get_int(&start,
2230 xbt_dynar_get_as(radical_ends, 0, char *));
2231 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2232 for (i = start; i <= end; i++) {
2233 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2234 res = random_generate(random);
2235 tmpbuf = bprintf("%s%d",random_id,i);
2236 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2241 XBT_INFO("Malformed radical");
2243 res = random_generate(random);
2244 rd_name = bprintf("%s_router",random_id);
2245 rd_value = bprintf("%f",res);
2246 xbt_dict_set(random_value, rd_name, rd_value, free);
2248 xbt_dynar_free(&radical_ends);
2251 xbt_dynar_free(&radical_elements);
2255 static void routing_parse_Erandom(void)
2257 xbt_dict_cursor_t cursor = NULL;
2261 xbt_dict_foreach(random_value, cursor, key, elem) {
2262 XBT_DEBUG("%s = %s",key,elem);
2269 * New methods to init the routing model component from the lua script
2273 * calling parse_S_AS_lua with lua values
2275 void routing_AS_init(const char *AS_id, const char *AS_routing)
2277 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
2281 * calling parse_E_AS_lua to fisnish the creation of routing component
2283 void routing_AS_end(const char *AS_id)
2285 parse_E_AS_lua((char *) AS_id);
2289 * add a host to the network element list
2292 void routing_add_host(const char *host_id)
2294 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2298 * Set a new link on the actual list of link for a route or ASroute
2300 void routing_add_link(const char *link_id)
2302 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2306 *Set the endpoints for a route
2308 void routing_set_route(const char *src_id, const char *dst_id)
2310 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2314 * Store the route by calling parse_E_route_store_route
2316 void routing_store_route(void)
2318 parse_E_route_store_route();