1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include <pcre.h> /* regular expression library */
10 #include "surf_routing_private.h"
11 #include "surf_routing.h"
14 int ROUTING_HOST_LEVEL; //Routing level
15 int SURF_CPU_LEVEL; //Surf cpu level
16 int SURF_WKS_LEVEL; //Surf workstation level
17 int SIMIX_HOST_LEVEL; //Simix level
18 int MSG_HOST_LEVEL; //Msg level
19 int SD_HOST_LEVEL; //Simdag level
20 int COORD_HOST_LEVEL; //Coordinates level
21 int NS3_HOST_LEVEL; //host node for ns3
24 int SD_LINK_LEVEL; //Simdag level
25 int SURF_LINK_LEVEL; //Surf level
26 int NS3_LINK_LEVEL; //link for ns3
28 xbt_lib_t as_router_lib;
29 int ROUTING_ASR_LEVEL; //Routing level
30 int COORD_ASR_LEVEL; //Coordinates level
31 int NS3_ASR_LEVEL; //host node for ns3
33 static xbt_dict_t patterns = NULL;
34 static xbt_dict_t random_value = NULL;
37 routing_global_t global_routing = NULL;
38 routing_component_t current_routing = NULL;
39 model_type_t current_routing_model = NULL;
41 /* global parse functions */
42 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
43 static const char *src = NULL; /* temporary store the source name of a route */
44 static const char *dst = NULL; /* temporary store the destination name of a route */
45 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
46 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
47 static double_f_cpvoid_t get_link_latency = NULL;
49 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
51 static void routing_parse_Speer(void); /* peer bypass */
52 static void routing_parse_Srandom(void); /* random bypass */
53 static void routing_parse_Erandom(void); /* random bypass */
55 static void routing_parse_Sconfig(void); /* config Tag */
56 static void routing_parse_Econfig(void); /* config Tag */
58 static char* replace_random_parameter(char * chaine);
59 static void clean_dict_random(void);
61 /* this lines are only for replace use like index in the model table */
66 SURF_MODEL_DIJKSTRACACHE,
73 struct s_model_type routing_models[] = { {"Full",
74 "Full routing data (fast, large memory requirements, fully expressive)",
80 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
81 model_floyd_create, model_floyd_load, model_floyd_unload,
84 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
85 model_dijkstra_create, model_dijkstra_both_load,
86 model_dijkstra_both_unload, model_dijkstra_both_end},
88 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
89 model_dijkstracache_create, model_dijkstra_both_load,
90 model_dijkstra_both_unload, model_dijkstra_both_end},
91 {"none", "No routing (usable with Constant network only)",
92 model_none_create, model_none_load, model_none_unload, model_none_end},
94 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
95 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
96 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
97 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
99 {NULL, NULL, NULL, NULL, NULL, NULL}
102 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
104 double src_coord, dst_coord;
106 src_coord = atof(xbt_dynar_get_as(src, index, char *));
107 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
109 return (src_coord-dst_coord)*(src_coord-dst_coord);
113 static double base_vivaldi_get_latency (const char *src, const char *dst)
115 double euclidean_dist;
116 xbt_dynar_t src_ctn, dst_ctn;
117 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
118 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
119 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
120 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
122 if(dst_ctn == NULL || src_ctn == NULL)
123 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
125 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
126 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
128 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
130 return euclidean_dist;
133 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
135 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
136 int need_to_clean = e_route?0:1;
138 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
139 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
140 if(need_to_clean) generic_free_extended_route(e_route);
143 return base_vivaldi_get_latency(src,dst);
148 * \brief Add a "host" to the network element list
150 static void parse_S_host(const char *host_id, const char* coord)
152 network_element_info_t info = NULL;
153 if (current_routing->hierarchy == SURF_ROUTING_NULL)
154 current_routing->hierarchy = SURF_ROUTING_BASE;
155 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
156 "Reading a host, processing unit \"%s\" already exists",
158 xbt_assert(current_routing->set_processing_unit,
159 "no defined method \"set_processing_unit\" in \"%s\"",
160 current_routing->name);
161 (*(current_routing->set_processing_unit)) (current_routing, host_id);
162 info = xbt_new0(s_network_element_info_t, 1);
163 info->rc_component = current_routing;
164 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
165 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
166 if (strcmp(coord,"")) {
167 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
168 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
169 xbt_dynar_shrink(ctn, 0);
170 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
174 static void parse_E_host(void)
176 xbt_dict_cursor_t cursor = NULL;
180 xbt_dict_foreach(current_property_set, cursor, key, elem) {
181 XBT_DEBUG("property : %s = %s",key,elem);
186 * \brief Add a host to the network element list from XML
188 static void parse_S_host_XML(void)
190 parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
192 static void parse_E_host_XML(void)
198 * \brief Add a host to the network element list from lua script
200 static void parse_S_host_lua(const char *host_id, const char *coord)
202 parse_S_host(host_id, coord);
207 * \brief Add a "router" to the network element list
209 static void parse_S_router(const char *router_id)
211 network_element_info_t info = NULL;
213 if (current_routing->hierarchy == SURF_ROUTING_NULL)
214 current_routing->hierarchy = SURF_ROUTING_BASE;
215 xbt_assert(!xbt_lib_get_or_null(as_router_lib,A_surfxml_router_id, ROUTING_ASR_LEVEL),
216 "Reading a router, processing unit \"%s\" already exists",
218 xbt_assert(current_routing->set_processing_unit,
219 "no defined method \"set_processing_unit\" in \"%s\"",
220 current_routing->name);
221 (*(current_routing->set_processing_unit)) (current_routing,
223 info = xbt_new0(s_network_element_info_t, 1);
224 info->rc_component = current_routing;
225 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
227 xbt_lib_set(as_router_lib,router_id,ROUTING_ASR_LEVEL,(void *) info);
228 if (strcmp(A_surfxml_router_coordinates,"")) {
229 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
230 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
231 xbt_dynar_shrink(ctn, 0);
232 xbt_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn);
237 * brief Add a "router" to the network element list from XML description
239 static void parse_S_router_XML(void)
241 return parse_S_router(A_surfxml_router_id);
245 * brief Add a "router" to the network element list from XML description
247 static void parse_S_router_lua(const char* router_id)
249 return parse_S_router(router_id);
253 * \brief Set the endponints for a route
255 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
257 if (src != NULL && dst != NULL && link_list != NULL)
258 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
262 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
263 "Some limits are null in the route between \"%s\" and \"%s\"",
265 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
269 * \brief Set the endpoints for a route from XML
271 static void parse_S_route_new_and_endpoints_XML(void)
273 parse_S_route_new_and_endpoints(A_surfxml_route_src,
274 A_surfxml_route_dst);
278 * \brief Set the endpoints for a route from lua
280 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
282 parse_S_route_new_and_endpoints(id_src, id_dst);
286 * \brief Set the endponints and gateways for a ASroute
288 static void parse_S_ASroute_new_and_endpoints(void)
290 if (src != NULL && dst != NULL && link_list != NULL)
291 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
292 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
293 src = A_surfxml_ASroute_src;
294 dst = A_surfxml_ASroute_dst;
295 gw_src = A_surfxml_ASroute_gw_src;
296 gw_dst = A_surfxml_ASroute_gw_dst;
297 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
298 || strlen(gw_dst) > 0,
299 "Some limits are null in the route between \"%s\" and \"%s\"",
301 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
305 * \brief Set the endponints for a bypassRoute
307 static void parse_S_bypassRoute_new_and_endpoints(void)
309 if (src != NULL && dst != NULL && link_list != NULL)
311 "Bypass Route between %s to %s can not be defined",
312 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
313 src = A_surfxml_bypassRoute_src;
314 dst = A_surfxml_bypassRoute_dst;
315 gw_src = A_surfxml_bypassRoute_gw_src;
316 gw_dst = A_surfxml_bypassRoute_gw_dst;
317 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
318 || strlen(gw_dst) > 0,
319 "Some limits are null in the route between \"%s\" and \"%s\"",
321 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
325 * \brief Set a new link on the actual list of link for a route or ASroute
327 static void parse_E_link_ctn_new_elem(const char *link_id)
330 val = xbt_strdup(link_id);
331 xbt_dynar_push(link_list, &val);
335 * \brief Set a new link on the actual list of link for a route or ASroute from XML
338 static void parse_E_link_ctn_new_elem_XML(void)
340 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
341 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
342 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
343 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
344 parse_E_link_ctn_new_elem(link_id);
347 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
348 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
349 parse_E_link_ctn_new_elem(link_id);
355 * \brief Set a new link on the actual list of link for a route or ASroute from lua
357 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
359 parse_E_link_ctn_new_elem(link_id);
363 * \brief Store the route by calling the set_route function of the current routing component
365 static void parse_E_route_store_route(void)
367 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
368 route->generic_route.link_list = link_list;
369 xbt_assert(current_routing->set_route,
370 "no defined method \"set_route\" in \"%s\"",
371 current_routing->name);
372 (*(current_routing->set_route)) (current_routing, src, dst, route);
379 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
381 static void parse_E_ASroute_store_route(void)
383 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
384 e_route->generic_route.link_list = link_list;
385 e_route->src_gateway = xbt_strdup(gw_src);
386 e_route->dst_gateway = xbt_strdup(gw_dst);
387 xbt_assert(current_routing->set_ASroute,
388 "no defined method \"set_ASroute\" in \"%s\"",
389 current_routing->name);
390 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
399 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
401 static void parse_E_bypassRoute_store_route(void)
403 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
404 e_route->generic_route.link_list = link_list;
405 e_route->src_gateway = xbt_strdup(gw_src);
406 e_route->dst_gateway = xbt_strdup(gw_dst);
407 xbt_assert(current_routing->set_bypassroute,
408 "no defined method \"set_bypassroute\" in \"%s\"",
409 current_routing->name);
410 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
420 * \brief Make a new routing component
422 * make the new structure and
423 * set the parsing functions to allows parsing the part of the routing tree
425 static void parse_S_AS(char *AS_id, char *AS_routing)
427 routing_component_t new_routing;
428 model_type_t model = NULL;
429 char *wanted = AS_routing;
431 /* seach the routing model */
432 for (cpt = 0; routing_models[cpt].name; cpt++)
433 if (!strcmp(wanted, routing_models[cpt].name))
434 model = &routing_models[cpt];
435 /* if its not exist, error */
437 fprintf(stderr, "Routing model %s not found. Existing models:\n",
439 for (cpt = 0; routing_models[cpt].name; cpt++)
440 if (!strcmp(wanted, routing_models[cpt].name))
441 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
442 routing_models[cpt].desc);
446 /* make a new routing component */
447 new_routing = (routing_component_t) (*(model->create)) ();
448 new_routing->routing = model;
449 new_routing->hierarchy = SURF_ROUTING_NULL;
450 new_routing->name = xbt_strdup(AS_id);
451 new_routing->routing_sons = xbt_dict_new();
453 /* Hack for Vivaldi */
454 if(!strcmp(model->name,"Vivaldi"))
455 new_routing->get_latency = vivaldi_get_link_latency;
457 if (current_routing == NULL && global_routing->root == NULL) {
459 /* it is the first one */
460 new_routing->routing_father = NULL;
461 global_routing->root = new_routing;
463 } else if (current_routing != NULL && global_routing->root != NULL) {
465 xbt_assert(!xbt_dict_get_or_null
466 (current_routing->routing_sons, AS_id),
467 "The AS \"%s\" already exists", AS_id);
468 /* it is a part of the tree */
469 new_routing->routing_father = current_routing;
470 /* set the father behavior */
471 if (current_routing->hierarchy == SURF_ROUTING_NULL)
472 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
473 /* add to the sons dictionary */
474 xbt_dict_set(current_routing->routing_sons, AS_id,
475 (void *) new_routing, NULL);
476 /* add to the father element list */
477 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
478 /* unload the prev parse rules */
479 (*(current_routing->routing->unload)) ();
482 THROWF(arg_error, 0, "All defined components must be belong to a AS");
484 /* set the new parse rules */
485 (*(new_routing->routing->load)) ();
486 /* set the new current component of the tree */
487 current_routing = new_routing;
491 * Detect the routing model type of the routing component from XML platforms
493 static void parse_S_AS_XML(void)
495 parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
499 * define the routing model type of routing component from lua script
501 static void parse_S_AS_lua(char *id, char *mode)
503 parse_S_AS(id, mode);
508 * \brief Finish the creation of a new routing component
510 * When you finish to read the routing component, other structures must be created.
511 * the "end" method allow to do that for any routing model type
513 static void parse_E_AS(const char *AS_id)
516 if (current_routing == NULL) {
517 THROWF(arg_error, 0, "Close AS(%s), that never open", AS_id);
519 network_element_info_t info = NULL;
520 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
521 "The AS \"%s\" already exists",current_routing->name);
522 info = xbt_new0(s_network_element_info_t, 1);
523 info->rc_component = current_routing->routing_father;
524 info->rc_type = SURF_NETWORK_ELEMENT_AS;
525 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
527 (*(current_routing->routing->unload)) ();
528 (*(current_routing->routing->end)) ();
529 current_routing = current_routing->routing_father;
530 if (current_routing != NULL)
531 (*(current_routing->routing->load)) ();
536 * \brief Finish the creation of a new routing component from XML
538 static void parse_E_AS_XML(void)
540 parse_E_AS(A_surfxml_AS_id);
544 * \brief Finish the creation of a new routing component from lua
546 static void parse_E_AS_lua(const char *id)
551 /* Aux Business methods */
554 * \brief Get the AS name of the element
556 * \param name the host name
559 static char* elements_As_name(const char *name)
561 routing_component_t as_comp;
563 /* (1) find the as where the host is located */
564 as_comp = ((network_element_info_t)
565 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
566 return as_comp->name;
571 * \brief Get the AS father and the first elements of the chain
573 * \param src the source host name
574 * \param dst the destination host name
576 * Get the common father of the to processing units, and the first different
577 * father in the chain
579 static xbt_dynar_t elements_father(const char *src, const char *dst)
582 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
584 xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
586 routing_component_t src_as, dst_as;
587 int index_src, index_dst, index_father_src, index_father_dst;
588 xbt_dynar_t path_src = NULL;
589 xbt_dynar_t path_dst = NULL;
590 routing_component_t current = NULL;
591 routing_component_t *current_src = NULL;
592 routing_component_t *current_dst = NULL;
593 routing_component_t *father = NULL;
595 /* (1) find the as where the src and dst are located */
596 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
597 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
598 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
599 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
600 src_as = ((network_element_info_t)src_data)->rc_component;
601 dst_as = ((network_element_info_t)dst_data)->rc_component;
605 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
608 /* (2) find the path to the root routing component */
609 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
611 while (current != NULL) {
612 xbt_dynar_push(path_src, ¤t);
613 current = current->routing_father;
615 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
617 while (current != NULL) {
618 xbt_dynar_push(path_dst, ¤t);
619 current = current->routing_father;
622 /* (3) find the common father */
623 index_src = path_src->used - 1;
624 index_dst = path_dst->used - 1;
625 current_src = xbt_dynar_get_ptr(path_src, index_src);
626 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
627 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
628 current_src = xbt_dynar_get_ptr(path_src, index_src);
629 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
635 current_src = xbt_dynar_get_ptr(path_src, index_src);
636 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
638 /* (4) they are not in the same routing component, make the path */
639 index_father_src = index_src + 1;
640 index_father_dst = index_dst + 1;
642 if (*current_src == *current_dst)
643 father = current_src;
645 father = xbt_dynar_get_ptr(path_src, index_father_src);
647 /* (5) result generation */
648 xbt_dynar_push(result, father); /* first same the father of src and dst */
649 xbt_dynar_push(result, current_src); /* second the first different father of src */
650 xbt_dynar_push(result, current_dst); /* three the first different father of dst */
652 xbt_dynar_free(&path_src);
653 xbt_dynar_free(&path_dst);
658 /* Global Business methods */
661 * \brief Recursive function for get_route
663 * \param src the source host name
664 * \param dst the destination host name
666 * This function is called by "get_route". It allows to walk recursively
667 * through the routing components tree.
669 static route_extended_t _get_route(const char *src, const char *dst)
673 unsigned int cpt = 0;
675 XBT_DEBUG("Solve route \"%s\" to \"%s\"", src, dst);
677 xbt_assert(src && dst, "bad parameters for \"_get_route\" method");
679 route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
682 xbt_dynar_t elem_father_list = elements_father(src, dst);
684 routing_component_t common_father =
685 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
686 routing_component_t src_father =
687 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
688 routing_component_t dst_father =
689 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
691 e_route = xbt_new0(s_route_extended_t, 1);
692 e_route->src_gateway = NULL;
693 e_route->dst_gateway = NULL;
694 e_route->generic_route.link_list =
695 xbt_dynar_new(global_routing->size_of_link, NULL);
697 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
700 (*(common_father->get_route)) (common_father, src, dst);
701 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
703 // FIXME (optim): faire une copie et pas une série de push
704 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
705 xbt_dynar_push(e_route->generic_route.link_list, &link);
707 generic_free_extended_route(e_route_cnt);
709 } else { /* SURF_ROUTING_RECURSIVE */
711 route_extended_t e_route_bypass = NULL;
713 if (common_father->get_bypass_route)
715 (*(common_father->get_bypass_route)) (common_father, src, dst);
718 e_route_cnt = e_route_bypass;
721 (*(common_father->get_route)) (common_father, src_father->name,
724 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
725 src_father->name, dst_father->name);
727 xbt_assert((e_route_cnt->src_gateway == NULL) ==
728 (e_route_cnt->dst_gateway == NULL),
729 "bad gateway for route between \"%s\" and \"%s\"", src,
732 if (strcmp(src, e_route_cnt->src_gateway)) {
733 e_route_src = _get_route(src, e_route_cnt->src_gateway);
734 xbt_assert(e_route_src, "no route between \"%s\" and \"%s\"", src,
735 e_route_cnt->src_gateway);
736 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
737 xbt_dynar_push(e_route->generic_route.link_list, &link);
741 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
742 xbt_dynar_push(e_route->generic_route.link_list, &link);
745 if (strcmp(e_route_cnt->dst_gateway, dst)) {
746 e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
747 xbt_assert(e_route_dst, "no route between \"%s\" and \"%s\"",
748 e_route_cnt->dst_gateway, dst);
749 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
750 xbt_dynar_push(e_route->generic_route.link_list, &link);
754 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
755 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
757 generic_free_extended_route(e_route_src);
758 generic_free_extended_route(e_route_cnt);
759 generic_free_extended_route(e_route_dst);
762 xbt_dynar_free(&elem_father_list);
767 static double _get_latency(const char *src, const char *dst)
769 double latency, latency_src, latency_dst = 0.0;
771 XBT_DEBUG("Solve route \"%s\" to \"%s\"", src, dst);
772 xbt_assert(src && dst, "bad parameters for \"_get_route\" method");
774 route_extended_t e_route_cnt;
776 xbt_dynar_t elem_father_list = elements_father(src, dst);
778 routing_component_t common_father =
779 xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
780 routing_component_t src_father =
781 xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
782 routing_component_t dst_father =
783 xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
785 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
788 (*(common_father->get_latency)) (common_father, src, dst, NULL);
789 xbt_assert(latency>=0, "no route between \"%s\" and \"%s\"", src,
792 } else { /* SURF_ROUTING_RECURSIVE */
793 route_extended_t e_route_bypass = NULL;
794 if (common_father->get_bypass_route)
796 (*(common_father->get_bypass_route)) (common_father, src, dst);
798 xbt_assert(!e_route_bypass,"Bypass cannot work yet with get_latency");
801 (*(common_father->get_route)) (common_father, src_father->name,
804 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
805 src_father->name, dst_father->name);
807 xbt_assert((e_route_cnt->src_gateway == NULL) ==
808 (e_route_cnt->dst_gateway == NULL),
809 "bad gateway for route between \"%s\" and \"%s\"", src,
812 latency = (*(common_father->get_latency)) (common_father, src_father->name, dst_father->name, e_route_cnt);
814 xbt_assert(latency>=0, "no route between \"%s\" and \"%s\"",
815 src_father->name, dst_father->name);
817 if (strcmp(src,e_route_cnt->src_gateway)) {
819 latency_src = _get_latency(src, e_route_cnt->src_gateway);
820 xbt_assert(latency_src>=0, "no route between \"%s\" and \"%s\"", src,
821 e_route_cnt->src_gateway);
822 latency += latency_src;
825 if (strcmp(e_route_cnt->dst_gateway,dst)) {
827 latency_dst = _get_latency(e_route_cnt->dst_gateway, dst);
828 xbt_assert(latency_dst>=0, "no route between \"%s\" and \"%s\"",
829 e_route_cnt->dst_gateway, dst);
830 latency += latency_dst;
835 xbt_dynar_free(&elem_father_list);
841 * \brief Generic method: find a route between hosts
843 * \param src the source host name
844 * \param dst the destination host name
846 * walk through the routing components tree and find a route between hosts
847 * by calling the differents "get_route" functions in each routing component.
848 * No need to free the returned dynar. It will be freed at the next call.
850 static xbt_dynar_t get_route(const char *src, const char *dst)
853 route_extended_t e_route;
855 e_route = _get_route(src, dst);
856 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
858 if (global_routing->last_route)
859 xbt_dynar_free(&(global_routing->last_route));
860 global_routing->last_route = e_route->generic_route.link_list;
862 if (e_route->src_gateway)
863 xbt_free(e_route->src_gateway);
864 if (e_route->dst_gateway)
865 xbt_free(e_route->dst_gateway);
869 return global_routing->last_route;
873 * \brief Generic method: find a route between hosts
875 * \param src the source host name
876 * \param dst the destination host name
878 * walk through the routing components tree and find a route between hosts
879 * by calling the differents "get_route" functions in each routing component.
880 * Leaves the caller the responsability to clean the returned dynar.
882 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
884 xbt_dynar_t d = get_route(src,dst);
885 global_routing->last_route = NULL;
890 static double get_latency(const char *src, const char *dst)
893 double latency = -1.0;
894 latency = _get_latency(src, dst);
895 xbt_assert(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst);
900 * \brief Recursive function for finalize
902 * \param rc the source host name
904 * This fuction is call by "finalize". It allow to finalize the
905 * AS or routing components. It delete all the structures.
907 static void _finalize(routing_component_t rc)
910 xbt_dict_cursor_t cursor = NULL;
912 routing_component_t elem;
913 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
916 xbt_dict_t tmp_sons = rc->routing_sons;
917 char *tmp_name = rc->name;
918 xbt_dict_free(&tmp_sons);
920 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
921 current_routing->name);
922 (*(rc->finalize)) (rc);
927 * \brief Generic method: delete all the routing structures
929 * walk through the routing components tree and delete the structures
930 * by calling the differents "finalize" functions in each routing component
932 static void finalize(void)
934 /* delete recursibly all the tree */
935 _finalize(global_routing->root);
936 /* delete last_route */
937 xbt_dynar_free(&(global_routing->last_route));
938 /* delete global routing structure */
939 xbt_free(global_routing);
942 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
944 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
946 //adding my one link routes
949 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
951 xbt_dynar_foreach(onelink_mine, cpt, link) {
952 xbt_dynar_push(ret, &link);
957 xbt_dict_cursor_t cursor = NULL;
958 routing_component_t rc_child;
959 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
960 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
962 xbt_dynar_foreach(onelink_child, cpt, link) {
963 xbt_dynar_push(ret, &link);
970 static xbt_dynar_t get_onelink_routes(void)
972 return recursive_get_onelink_routes(global_routing->root);
975 e_surf_network_element_type_t get_network_element_type(const char
978 network_element_info_t rc = NULL;
980 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
981 if(rc) return rc->rc_type;
983 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
984 if(rc) return rc->rc_type;
986 return SURF_NETWORK_ELEMENT_NULL;
990 * \brief Generic method: create the global routing schema
992 * Make a global routing structure and set all the parsing functions.
994 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
996 /* config the uniq global routing */
997 global_routing = xbt_new0(s_routing_global_t, 1);
998 global_routing->root = NULL;
999 global_routing->get_route = get_route;
1000 global_routing->get_latency = get_latency;
1001 global_routing->get_route_no_cleanup = get_route_no_cleanup;
1002 global_routing->get_onelink_routes = get_onelink_routes;
1003 global_routing->get_network_element_type = get_network_element_type;
1004 global_routing->finalize = finalize;
1005 global_routing->loopback = loopback;
1006 global_routing->size_of_link = size_of_links;
1007 global_routing->last_route = NULL;
1008 get_link_latency = get_link_latency_fun;
1009 /* no current routing at moment */
1010 current_routing = NULL;
1012 /* parse generic elements */
1013 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
1014 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
1015 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
1017 surfxml_add_callback(STag_surfxml_route_cb_list,
1018 &parse_S_route_new_and_endpoints_XML);
1019 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
1020 &parse_S_ASroute_new_and_endpoints);
1021 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
1022 &parse_S_bypassRoute_new_and_endpoints);
1024 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
1025 &parse_E_link_ctn_new_elem_XML);
1027 surfxml_add_callback(ETag_surfxml_route_cb_list,
1028 &parse_E_route_store_route);
1029 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
1030 &parse_E_ASroute_store_route);
1031 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
1032 &parse_E_bypassRoute_store_route);
1034 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
1035 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
1037 surfxml_add_callback(STag_surfxml_cluster_cb_list,
1038 &routing_parse_Scluster);
1040 surfxml_add_callback(STag_surfxml_peer_cb_list,
1041 &routing_parse_Speer);
1043 surfxml_add_callback(ETag_surfxml_platform_cb_list,
1044 &clean_dict_random);
1047 instr_routing_define_callbacks();
1051 void surf_parse_add_callback_config(void)
1053 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1054 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1055 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1056 surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
1057 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1060 void surf_parse_models_setup()
1062 routing_parse_Erandom();
1063 surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1064 surf_config_models_setup(platform_filename);
1065 free(platform_filename);
1068 /* ************************************************** */
1069 /* ********** PATERN FOR NEW ROUTING **************** */
1071 /* The minimal configuration of a new routing model need the next functions,
1072 * also you need to set at the start of the file, the new model in the model
1073 * list. Remember keep the null ending of the list.
1075 /*** Routing model structure ***/
1077 // s_routing_component_t generic_routing;
1078 // /* things that your routing model need */
1079 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1081 /*** Parse routing model functions ***/
1082 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1083 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1084 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1085 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1086 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1088 /*** Business methods ***/
1089 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1090 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1091 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1093 /*** Creation routing model functions ***/
1094 // static void* model_NEW_create(void) {
1095 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1096 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1097 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1098 // new_component->generic_routing.set_route = model_NEW_set_route;
1099 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1100 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1101 // new_component->generic_routing.get_route = NEW_get_route;
1102 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1103 // new_component->generic_routing.finalize = NEW_finalize;
1104 // /* initialization of internal structures */
1105 // return new_component;
1106 // } /* mandatory */
1107 // static void model_NEW_load(void) {} /* mandatory */
1108 // static void model_NEW_unload(void) {} /* mandatory */
1109 // static void model_NEW_end(void) {} /* mandatory */
1111 /* ************************************************************************** */
1112 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1114 void generic_set_processing_unit(routing_component_t rc,
1117 XBT_DEBUG("Load process unit \"%s\"", name);
1118 int *id = xbt_new0(int, 1);
1119 xbt_dict_t _to_index;
1120 _to_index = current_routing->to_index;
1121 *id = xbt_dict_length(_to_index);
1122 xbt_dict_set(_to_index, name, id, xbt_free);
1125 void generic_set_autonomous_system(routing_component_t rc,
1128 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1129 int *id = xbt_new0(int, 1);
1130 xbt_dict_t _to_index;
1131 _to_index = current_routing->to_index;
1132 *id = xbt_dict_length(_to_index);
1133 xbt_dict_set(_to_index, name, id, xbt_free);
1136 int surf_pointer_resource_cmp(const void *a, const void *b)
1141 int surf_link_resource_cmp(const void *a, const void *b)
1143 return !!memcmp(a,b,global_routing->size_of_link);
1146 void generic_set_bypassroute(routing_component_t rc,
1147 const char *src, const char *dst,
1148 route_extended_t e_route)
1150 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1151 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1154 route_name = bprintf("%s#%s", src, dst);
1155 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1156 "Invalid count of links, must be greater than zero (%s,%s)",
1158 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1159 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1160 src, e_route->src_gateway, dst, e_route->dst_gateway);
1162 route_extended_t new_e_route =
1163 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1164 xbt_dynar_free(&(e_route->generic_route.link_list));
1167 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1168 (void (*)(void *)) generic_free_extended_route);
1169 xbt_free(route_name);
1172 /* ************************************************************************** */
1173 /* *********************** GENERIC BUSINESS METHODS ************************* */
1175 double generic_get_link_latency(routing_component_t rc,
1176 const char *src, const char *dst,
1177 route_extended_t route)
1179 int need_to_clean = route?0:1;
1182 double latency = 0.0;
1184 route = route?route:rc->get_route(rc,src,dst);
1186 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1187 latency += get_link_latency(link);
1189 if(need_to_clean) generic_free_extended_route(route);
1193 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1195 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1198 route_extended_t generic_get_bypassroute(routing_component_t rc,
1202 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1203 routing_component_t src_as, dst_as;
1204 int index_src, index_dst;
1205 xbt_dynar_t path_src = NULL;
1206 xbt_dynar_t path_dst = NULL;
1207 routing_component_t current = NULL;
1208 routing_component_t *current_src = NULL;
1209 routing_component_t *current_dst = NULL;
1211 /* (1) find the as where the src and dst are located */
1212 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1213 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1214 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1215 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1217 if(src_data == NULL || dst_data == NULL)
1218 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1219 src, dst, rc->name);
1221 src_as = ((network_element_info_t)src_data)->rc_component;
1222 dst_as = ((network_element_info_t)dst_data)->rc_component;
1224 /* (2) find the path to the root routing component */
1225 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1227 while (current != NULL) {
1228 xbt_dynar_push(path_src, ¤t);
1229 current = current->routing_father;
1231 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1233 while (current != NULL) {
1234 xbt_dynar_push(path_dst, ¤t);
1235 current = current->routing_father;
1238 /* (3) find the common father */
1239 index_src = path_src->used - 1;
1240 index_dst = path_dst->used - 1;
1241 current_src = xbt_dynar_get_ptr(path_src, index_src);
1242 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1243 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1244 routing_component_t *tmp_src, *tmp_dst;
1245 tmp_src = xbt_dynar_pop_ptr(path_src);
1246 tmp_dst = xbt_dynar_pop_ptr(path_dst);
1249 current_src = xbt_dynar_get_ptr(path_src, index_src);
1250 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1253 int max_index_src = path_src->used - 1;
1254 int max_index_dst = path_dst->used - 1;
1256 int max_index = max(max_index_src, max_index_dst);
1259 route_extended_t e_route_bypass = NULL;
1261 for (max = 0; max <= max_index; max++) {
1262 for (i = 0; i < max; i++) {
1263 if (i <= max_index_src && max <= max_index_dst) {
1264 char *route_name = bprintf("%s#%s",
1265 (*(routing_component_t *)
1267 (path_src, i)))->name,
1268 (*(routing_component_t *)
1270 (path_dst, max)))->name);
1272 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1273 xbt_free(route_name);
1277 if (max <= max_index_src && i <= max_index_dst) {
1278 char *route_name = bprintf("%s#%s",
1279 (*(routing_component_t *)
1281 (path_src, max)))->name,
1282 (*(routing_component_t *)
1284 (path_dst, i)))->name);
1286 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1287 xbt_free(route_name);
1296 if (max <= max_index_src && max <= max_index_dst) {
1297 char *route_name = bprintf("%s#%s",
1298 (*(routing_component_t *)
1300 (path_src, max)))->name,
1301 (*(routing_component_t *)
1303 (path_dst, max)))->name);
1304 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1305 xbt_free(route_name);
1311 xbt_dynar_free(&path_src);
1312 xbt_dynar_free(&path_dst);
1314 route_extended_t new_e_route = NULL;
1316 if (e_route_bypass) {
1318 unsigned int cpt = 0;
1319 new_e_route = xbt_new0(s_route_extended_t, 1);
1320 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1321 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1322 new_e_route->generic_route.link_list =
1323 xbt_dynar_new(global_routing->size_of_link, NULL);
1324 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1325 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1332 /* ************************************************************************** */
1333 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1336 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1337 void *data, int order)
1343 xbt_dynar_t links = NULL, links_id = NULL;
1345 new_route = xbt_new0(s_route_t, 1);
1346 new_route->link_list =
1347 xbt_dynar_new(global_routing->size_of_link, NULL);
1349 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1350 "the hierarchy type is not SURF_ROUTING_BASE");
1352 links = ((route_t) data)->link_list;
1355 links_id = new_route->link_list;
1357 xbt_dynar_foreach(links, cpt, link_name) {
1360 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1363 xbt_dynar_push(links_id, &link);
1365 xbt_dynar_unshift(links_id, &link);
1367 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1374 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1375 void *data, int order)
1379 route_extended_t e_route, new_e_route;
1382 xbt_dynar_t links = NULL, links_id = NULL;
1384 new_e_route = xbt_new0(s_route_extended_t, 1);
1385 new_e_route->generic_route.link_list =
1386 xbt_dynar_new(global_routing->size_of_link, NULL);
1387 new_e_route->src_gateway = NULL;
1388 new_e_route->dst_gateway = NULL;
1390 xbt_assert(hierarchy == SURF_ROUTING_BASE
1391 || hierarchy == SURF_ROUTING_RECURSIVE,
1392 "the hierarchy type is not defined");
1394 if (hierarchy == SURF_ROUTING_BASE) {
1396 route = (route_t) data;
1397 links = route->link_list;
1399 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1401 e_route = (route_extended_t) data;
1402 xbt_assert(e_route->src_gateway
1403 && e_route->dst_gateway, "bad gateway, is null");
1404 links = e_route->generic_route.link_list;
1406 /* remeber not erase the gateway names */
1407 new_e_route->src_gateway = strdup(e_route->src_gateway);
1408 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1411 links_id = new_e_route->generic_route.link_list;
1413 xbt_dynar_foreach(links, cpt, link_name) {
1416 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1419 xbt_dynar_push(links_id, &link);
1421 xbt_dynar_unshift(links_id, &link);
1423 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1429 void generic_free_route(route_t route)
1432 xbt_dynar_free(&(route->link_list));
1437 void generic_free_extended_route(route_extended_t e_route)
1440 xbt_dynar_free(&(e_route->generic_route.link_list));
1441 if (e_route->src_gateway)
1442 xbt_free(e_route->src_gateway);
1443 if (e_route->dst_gateway)
1444 xbt_free(e_route->dst_gateway);
1449 static routing_component_t generic_as_exist(routing_component_t find_from,
1450 routing_component_t to_find)
1452 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1453 xbt_dict_cursor_t cursor = NULL;
1456 routing_component_t elem;
1457 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1458 if (to_find == elem || generic_as_exist(elem, to_find)) {
1469 generic_autonomous_system_exist(routing_component_t rc, char *element)
1471 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1472 routing_component_t element_as, result, elem;
1473 xbt_dict_cursor_t cursor = NULL;
1475 element_as = ((network_element_info_t)
1476 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1477 result = ((routing_component_t) - 1);
1478 if (element_as != rc)
1479 result = generic_as_exist(rc, element_as);
1483 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1484 found = !strcmp(elem->name, element);
1495 generic_processing_units_exist(routing_component_t rc, char *element)
1497 routing_component_t element_as;
1498 element_as = ((network_element_info_t)
1499 xbt_lib_get_or_null(host_lib,
1500 element, ROUTING_HOST_LEVEL))->rc_component;
1501 if (element_as == rc)
1503 return generic_as_exist(rc, element_as);
1506 void generic_src_dst_check(routing_component_t rc, const char *src,
1510 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1511 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1512 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1513 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1515 if(src_data == NULL || dst_data == NULL)
1516 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1517 src, dst, rc->name);
1519 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1520 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1522 if(src_as != dst_as)
1523 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1524 src, src_as->name, dst, dst_as->name);
1526 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1527 src,dst,src_as->name, dst_as->name,rc->name);
1530 static void routing_parse_Sconfig(void)
1532 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1535 static void routing_parse_Econfig(void)
1537 xbt_dict_cursor_t cursor = NULL;
1541 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1542 cfg = bprintf("%s:%s",key,elem);
1543 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1544 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1546 XBT_INFO("The custom configuration '%s' is already define by user!",key);
1549 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1552 void routing_parse_Scluster(void)
1554 static int AX_ptr = 0;
1556 char *cluster_id = A_surfxml_cluster_id;
1557 char *cluster_prefix = A_surfxml_cluster_prefix;
1558 char *cluster_suffix = A_surfxml_cluster_suffix;
1559 char *cluster_radical = A_surfxml_cluster_radical;
1560 char *cluster_power = A_surfxml_cluster_power;
1561 char *cluster_core = A_surfxml_cluster_core;
1562 char *cluster_bw = A_surfxml_cluster_bw;
1563 char *cluster_lat = A_surfxml_cluster_lat;
1564 char *temp_cluster_bw = NULL;
1565 char *temp_cluster_lat = NULL;
1566 char *temp_cluster_power = NULL;
1567 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1568 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1569 char *cluster_availability_file = A_surfxml_cluster_availability_file;
1570 char *cluster_state_file = A_surfxml_cluster_state_file;
1571 char *host_id, *groups, *link_id = NULL;
1572 char *router_id, *link_backbone;
1573 char *availability_file = xbt_strdup(cluster_availability_file);
1574 char *state_file = xbt_strdup(cluster_state_file);
1576 if(xbt_dict_size(patterns)==0)
1577 patterns = xbt_dict_new();
1579 xbt_dict_set(patterns,"id",cluster_id,NULL);
1580 xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
1581 xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
1583 #ifdef HAVE_PCRE_LIB
1584 char *route_src_dst;
1588 xbt_dynar_t radical_elements;
1589 xbt_dynar_t radical_ends;
1590 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
1591 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
1593 #ifndef HAVE_PCRE_LIB
1594 xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
1595 char *route_src, *route_dst;
1599 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1600 static unsigned int surfxml_buffer_stack_stack[1024];
1602 surfxml_buffer_stack_stack[0] = 0;
1604 surfxml_bufferstack_push(1);
1606 SURFXML_BUFFER_SET(AS_id, cluster_id);
1607 #ifdef HAVE_PCRE_LIB
1608 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
1609 XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
1611 SURFXML_BUFFER_SET(AS_routing, "Full");
1612 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
1614 SURFXML_START_TAG(AS);
1616 radical_elements = xbt_str_split(cluster_radical, ",");
1617 xbt_dynar_foreach(radical_elements, iter, groups) {
1618 radical_ends = xbt_str_split(groups, "-");
1619 switch (xbt_dynar_length(radical_ends)) {
1621 surf_parse_get_int(&start,
1622 xbt_dynar_get_as(radical_ends, 0, char *));
1623 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
1624 #ifndef HAVE_PCRE_LIB
1625 xbt_dynar_push_as(tab_elements_num, int, start);
1627 link_id = bprintf("%s_link_%d", cluster_id, start);
1629 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1630 temp_cluster_power = xbt_strdup(cluster_power);
1631 temp_cluster_power = replace_random_parameter(temp_cluster_power);
1632 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1633 A_surfxml_host_state = A_surfxml_host_state_ON;
1634 SURFXML_BUFFER_SET(host_id, host_id);
1635 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1636 SURFXML_BUFFER_SET(host_core, cluster_core);
1637 SURFXML_BUFFER_SET(host_availability, "1.0");
1638 SURFXML_BUFFER_SET(host_coordinates, "");
1639 xbt_free(availability_file);
1640 availability_file = xbt_strdup(cluster_availability_file);
1641 xbt_free(state_file);
1642 state_file = xbt_strdup(cluster_state_file);
1643 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1644 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1645 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1646 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1647 XBT_DEBUG("</host>");
1648 SURFXML_START_TAG(host);
1649 SURFXML_END_TAG(host);
1652 temp_cluster_bw = xbt_strdup(cluster_bw);
1653 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1654 temp_cluster_lat = xbt_strdup(cluster_lat);
1655 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1656 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1657 A_surfxml_link_state = A_surfxml_link_state_ON;
1658 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1659 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1660 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1661 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1662 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1663 SURFXML_BUFFER_SET(link_id, link_id);
1664 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1665 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1666 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1667 SURFXML_BUFFER_SET(link_latency_file, "");
1668 SURFXML_BUFFER_SET(link_state_file, "");
1669 SURFXML_START_TAG(link);
1670 SURFXML_END_TAG(link);
1672 xbt_free(temp_cluster_bw);
1673 xbt_free(temp_cluster_lat);
1674 xbt_free(temp_cluster_power);
1681 surf_parse_get_int(&start,
1682 xbt_dynar_get_as(radical_ends, 0, char *));
1683 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1684 for (i = start; i <= end; i++) {
1685 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
1686 #ifndef HAVE_PCRE_LIB
1687 xbt_dynar_push_as(tab_elements_num, int, i);
1689 link_id = bprintf("%s_link_%d", cluster_id, i);
1691 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1692 temp_cluster_power = xbt_strdup(cluster_power);
1693 temp_cluster_power = replace_random_parameter(temp_cluster_power);
1694 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1695 A_surfxml_host_state = A_surfxml_host_state_ON;
1696 SURFXML_BUFFER_SET(host_id, host_id);
1697 SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1698 SURFXML_BUFFER_SET(host_core, cluster_core);
1699 SURFXML_BUFFER_SET(host_availability, "1.0");
1700 SURFXML_BUFFER_SET(host_coordinates, "");
1701 xbt_free(availability_file);
1702 availability_file = xbt_strdup(cluster_availability_file);
1703 xbt_free(state_file);
1704 state_file = xbt_strdup(cluster_state_file);
1705 XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1706 XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1707 SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1708 SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1709 XBT_DEBUG("</host>");
1710 SURFXML_START_TAG(host);
1711 SURFXML_END_TAG(host);
1713 xbt_free(temp_cluster_power);
1715 temp_cluster_bw = xbt_strdup(cluster_bw);
1716 temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1717 temp_cluster_lat = xbt_strdup(cluster_lat);
1718 temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1719 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1720 A_surfxml_link_state = A_surfxml_link_state_ON;
1721 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1722 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1723 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1724 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1725 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1726 SURFXML_BUFFER_SET(link_id, link_id);
1727 SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1728 SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1729 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1730 SURFXML_BUFFER_SET(link_latency_file, "");
1731 SURFXML_BUFFER_SET(link_state_file, "");
1732 SURFXML_START_TAG(link);
1733 SURFXML_END_TAG(link);
1735 xbt_free(temp_cluster_bw);
1736 xbt_free(temp_cluster_lat);
1743 XBT_DEBUG("Malformed radical");
1746 xbt_dynar_free(&radical_ends);
1748 xbt_dynar_free(&radical_elements);
1752 bprintf("%s%s_router%s", cluster_prefix, cluster_id,
1754 //link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
1755 link_backbone = bprintf("%s_backbone", cluster_id);
1757 XBT_DEBUG("<router id=\"%s\"/>", router_id);
1758 SURFXML_BUFFER_SET(router_id, router_id);
1759 SURFXML_BUFFER_SET(router_coordinates, "");
1760 SURFXML_START_TAG(router);
1761 SURFXML_END_TAG(router);
1764 // xbt_dict_set(patterns, "radical", xbt_strdup("_router"), xbt_free);
1765 // temp_cluster_bw = xbt_strdup(cluster_bw);
1766 // temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1767 // temp_cluster_lat = xbt_strdup(cluster_lat);
1768 // temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1769 // XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,temp_cluster_bw, temp_cluster_lat);
1770 // A_surfxml_link_state = A_surfxml_link_state_ON;
1771 // A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1772 // if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1773 // {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1774 // if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1775 // {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1776 // SURFXML_BUFFER_SET(link_id, link_router);
1777 // SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1778 // SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1779 // SURFXML_BUFFER_SET(link_bandwidth_file, "");
1780 // SURFXML_BUFFER_SET(link_latency_file, "");
1781 // SURFXML_BUFFER_SET(link_state_file, "");
1782 // SURFXML_START_TAG(link);
1783 // SURFXML_END_TAG(link);
1785 // xbt_free(temp_cluster_bw);
1786 // xbt_free(temp_cluster_lat);
1788 XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
1789 A_surfxml_link_state = A_surfxml_link_state_ON;
1790 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1791 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1792 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1793 SURFXML_BUFFER_SET(link_id, link_backbone);
1794 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
1795 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
1796 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1797 SURFXML_BUFFER_SET(link_latency_file, "");
1798 SURFXML_BUFFER_SET(link_state_file, "");
1799 SURFXML_START_TAG(link);
1800 SURFXML_END_TAG(link);
1804 #ifdef HAVE_PCRE_LIB
1805 char *new_suffix = xbt_strdup("");
1807 radical_elements = xbt_str_split(cluster_suffix, ".");
1808 xbt_dynar_foreach(radical_elements, iter, groups) {
1809 if (strcmp(groups, "")) {
1810 char *old_suffix = new_suffix;
1811 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1815 route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
1816 xbt_dynar_free(&radical_elements);
1819 char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
1820 char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
1821 char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
1823 //from router to router
1824 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, router_id);
1825 XBT_DEBUG("symmetrical=\"NO\">");
1826 SURFXML_BUFFER_SET(route_src, router_id);
1827 SURFXML_BUFFER_SET(route_dst, router_id);
1828 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1829 SURFXML_START_TAG(route);
1831 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1832 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1833 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1834 SURFXML_START_TAG(link_ctn);
1835 SURFXML_END_TAG(link_ctn);
1837 XBT_DEBUG("</route>");
1838 SURFXML_END_TAG(route);
1840 //from host to router
1841 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, router_id);
1842 XBT_DEBUG("symmetrical=\"NO\">");
1843 SURFXML_BUFFER_SET(route_src, route_src_dst);
1844 SURFXML_BUFFER_SET(route_dst, router_id);
1845 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1846 SURFXML_START_TAG(route);
1848 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1849 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1850 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1851 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1852 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1853 SURFXML_START_TAG(link_ctn);
1854 SURFXML_END_TAG(link_ctn);
1856 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1857 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1858 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1859 SURFXML_START_TAG(link_ctn);
1860 SURFXML_END_TAG(link_ctn);
1862 XBT_DEBUG("</route>");
1863 SURFXML_END_TAG(route);
1865 //from router to host
1866 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, route_src_dst);
1867 XBT_DEBUG("symmetrical=\"NO\">");
1868 SURFXML_BUFFER_SET(route_src, router_id);
1869 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1870 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1871 SURFXML_START_TAG(route);
1873 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1874 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1875 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1876 SURFXML_START_TAG(link_ctn);
1877 SURFXML_END_TAG(link_ctn);
1879 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1880 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1881 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1882 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1883 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1884 SURFXML_START_TAG(link_ctn);
1885 SURFXML_END_TAG(link_ctn);
1887 XBT_DEBUG("</route>");
1888 SURFXML_END_TAG(route);
1891 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
1892 XBT_DEBUG("symmetrical=\"NO\">");
1893 SURFXML_BUFFER_SET(route_src, route_src_dst);
1894 SURFXML_BUFFER_SET(route_dst, route_src_dst);
1895 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1896 SURFXML_START_TAG(route);
1898 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1899 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1900 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1901 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1902 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1903 SURFXML_START_TAG(link_ctn);
1904 SURFXML_END_TAG(link_ctn);
1906 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1907 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1908 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1909 SURFXML_START_TAG(link_ctn);
1910 SURFXML_END_TAG(link_ctn);
1912 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1913 SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1914 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1915 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1916 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1917 SURFXML_START_TAG(link_ctn);
1918 SURFXML_END_TAG(link_ctn);
1920 XBT_DEBUG("</route>");
1921 SURFXML_END_TAG(route);
1923 free(pcre_link_dst);
1924 free(pcre_link_backbone);
1925 free(pcre_link_src);
1926 free(route_src_dst);
1928 for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
1929 for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
1930 if (i == xbt_dynar_length(tab_elements_num)) {
1931 route_src = router_id;
1934 bprintf("%s%d%s", cluster_prefix,
1935 xbt_dynar_get_as(tab_elements_num, i, int),
1939 if (j == xbt_dynar_length(tab_elements_num)) {
1940 route_dst = router_id;
1943 bprintf("%s%d%s", cluster_prefix,
1944 xbt_dynar_get_as(tab_elements_num, j, int),
1948 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
1949 XBT_DEBUG("symmetrical=\"NO\">");
1950 SURFXML_BUFFER_SET(route_src, route_src);
1951 SURFXML_BUFFER_SET(route_dst, route_dst);
1952 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1953 SURFXML_START_TAG(route);
1955 if (i != xbt_dynar_length(tab_elements_num)){
1957 bprintf("%s_link_%d", cluster_id,
1958 xbt_dynar_get_as(tab_elements_num, i, int));
1959 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_src);
1960 SURFXML_BUFFER_SET(link_ctn_id, route_src);
1961 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1962 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1963 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1964 SURFXML_START_TAG(link_ctn);
1965 SURFXML_END_TAG(link_ctn);
1969 XBT_DEBUG("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
1970 SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
1971 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1972 SURFXML_START_TAG(link_ctn);
1973 SURFXML_END_TAG(link_ctn);
1975 if (j != xbt_dynar_length(tab_elements_num)) {
1977 bprintf("%s_link_%d", cluster_id,
1978 xbt_dynar_get_as(tab_elements_num, j, int));
1979 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_dst);
1980 SURFXML_BUFFER_SET(link_ctn_id, route_dst);
1981 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1982 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1983 {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1984 SURFXML_START_TAG(link_ctn);
1985 SURFXML_END_TAG(link_ctn);
1989 XBT_DEBUG("</route>");
1990 SURFXML_END_TAG(route);
1993 xbt_dynar_free(&tab_elements_num);
1998 free(link_backbone);
1999 //free(link_router);
2000 xbt_dict_free(&patterns);
2001 free(availability_file);
2005 SURFXML_END_TAG(AS);
2008 surfxml_bufferstack_pop(1);
2011 * This function take a string and replace parameters from patterns dict.
2012 * It returns the new value.
2014 static char* replace_random_parameter(char * string)
2016 char *test_string = NULL;
2018 if(xbt_dict_size(random_value)==0)
2021 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
2022 test_string = bprintf("${%s}", string);
2023 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
2025 if (strcmp(test_string,"")) { //if not empty, keep this value.
2027 string = test_string;
2028 } //In other case take old value (without ${})
2034 static void clean_dict_random(void)
2036 xbt_dict_free(&random_value);
2037 xbt_dict_free(&patterns);
2040 static void routing_parse_Speer(void)
2042 static int AX_ptr = 0;
2044 char *peer_id = A_surfxml_peer_id;
2045 char *peer_power = A_surfxml_peer_power;
2046 char *peer_bw_in = A_surfxml_peer_bw_in;
2047 char *peer_bw_out = A_surfxml_peer_bw_out;
2048 char *peer_lat = A_surfxml_peer_lat;
2049 char *peer_coord = A_surfxml_peer_coordinates;
2050 char *peer_state_file = A_surfxml_peer_state_file;
2051 char *peer_availability_file = A_surfxml_peer_availability_file;
2053 char *host_id = NULL;
2054 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
2056 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
2057 static unsigned int surfxml_buffer_stack_stack[1024];
2059 surfxml_buffer_stack_stack[0] = 0;
2061 surfxml_bufferstack_push(1);
2063 SURFXML_BUFFER_SET(AS_id, peer_id);
2065 SURFXML_BUFFER_SET(AS_routing, "Full");
2066 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
2068 SURFXML_START_TAG(AS);
2071 host_id = bprintf("peer_%s", peer_id);
2072 router_id = bprintf("router_%s", peer_id);
2073 link_id_up = bprintf("link_%s_up", peer_id);
2074 link_id_down = bprintf("link_%s_down", peer_id);
2076 link_router = bprintf("%s_link_router", peer_id);
2077 link_backbone = bprintf("%s_backbone", peer_id);
2079 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
2080 A_surfxml_host_state = A_surfxml_host_state_ON;
2081 SURFXML_BUFFER_SET(host_id, host_id);
2082 SURFXML_BUFFER_SET(host_power, peer_power);
2083 SURFXML_BUFFER_SET(host_availability, "1.0");
2084 SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
2085 SURFXML_BUFFER_SET(host_state_file, peer_state_file);
2086 SURFXML_BUFFER_SET(host_coordinates, "");
2087 SURFXML_START_TAG(host);
2088 SURFXML_END_TAG(host);
2090 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
2091 SURFXML_BUFFER_SET(router_id, router_id);
2092 SURFXML_BUFFER_SET(router_coordinates, peer_coord);
2093 SURFXML_START_TAG(router);
2094 SURFXML_END_TAG(router);
2096 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
2097 A_surfxml_link_state = A_surfxml_link_state_ON;
2098 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2099 SURFXML_BUFFER_SET(link_id, link_id_up);
2100 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
2101 SURFXML_BUFFER_SET(link_latency, peer_lat);
2102 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2103 SURFXML_BUFFER_SET(link_latency_file, "");
2104 SURFXML_BUFFER_SET(link_state_file, "");
2105 SURFXML_START_TAG(link);
2106 SURFXML_END_TAG(link);
2108 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
2109 A_surfxml_link_state = A_surfxml_link_state_ON;
2110 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2111 SURFXML_BUFFER_SET(link_id, link_id_down);
2112 SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
2113 SURFXML_BUFFER_SET(link_latency, peer_lat);
2114 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2115 SURFXML_BUFFER_SET(link_latency_file, "");
2116 SURFXML_BUFFER_SET(link_state_file, "");
2117 SURFXML_START_TAG(link);
2118 SURFXML_END_TAG(link);
2123 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
2124 XBT_DEBUG("symmetrical=\"NO\">");
2125 SURFXML_BUFFER_SET(route_src, host_id);
2126 SURFXML_BUFFER_SET(route_dst, router_id);
2127 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2128 SURFXML_START_TAG(route);
2130 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
2131 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
2132 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2133 SURFXML_START_TAG(link_ctn);
2134 SURFXML_END_TAG(link_ctn);
2136 XBT_DEBUG("</route>");
2137 SURFXML_END_TAG(route);
2140 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
2141 XBT_DEBUG("symmetrical=\"NO\">");
2142 SURFXML_BUFFER_SET(route_src, router_id);
2143 SURFXML_BUFFER_SET(route_dst, host_id);
2144 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2145 SURFXML_START_TAG(route);
2147 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
2148 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
2149 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2150 SURFXML_START_TAG(link_ctn);
2151 SURFXML_END_TAG(link_ctn);
2153 XBT_DEBUG("</route>");
2154 SURFXML_END_TAG(route);
2157 SURFXML_END_TAG(AS);
2160 //xbt_dynar_free(&tab_elements_num);
2164 free(link_backbone);
2167 surfxml_bufferstack_pop(1);
2170 static void routing_parse_Srandom(void)
2172 double mean, std, min, max, seed;
2173 char *random_id = A_surfxml_random_id;
2174 char *random_radical = A_surfxml_random_radical;
2175 char *rd_name = NULL;
2177 surf_parse_get_double(&mean,A_surfxml_random_mean);
2178 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2179 surf_parse_get_double(&min,A_surfxml_random_min);
2180 surf_parse_get_double(&max,A_surfxml_random_max);
2181 surf_parse_get_double(&seed,A_surfxml_random_seed);
2185 random_data_t random = xbt_new0(s_random_data_t, 1);
2188 xbt_dynar_t radical_elements;
2192 xbt_dynar_t radical_ends;
2194 random->generator = A_surfxml_random_generator;
2195 random->seed = seed;
2199 /* Check user stupidities */
2201 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2203 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2206 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2209 /* normalize the mean and standard deviation before storing */
2210 random->mean = (mean - min) / (max - min);
2211 random->std = std / (max - min);
2213 if (random->mean * (1 - random->mean) < random->std * random->std)
2214 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2215 random->mean, random->std);
2217 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2227 if(xbt_dict_size(random_value)==0)
2228 random_value = xbt_dict_new();
2230 if(!strcmp(random_radical,""))
2232 res = random_generate(random);
2233 rd_value = bprintf("%f",res);
2234 xbt_dict_set(random_value, random_id, rd_value, free);
2238 radical_elements = xbt_str_split(random_radical, ",");
2239 xbt_dynar_foreach(radical_elements, iter, groups) {
2240 radical_ends = xbt_str_split(groups, "-");
2241 switch (xbt_dynar_length(radical_ends)) {
2243 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2244 res = random_generate(random);
2245 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2246 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2250 case 2: surf_parse_get_int(&start,
2251 xbt_dynar_get_as(radical_ends, 0, char *));
2252 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2253 for (i = start; i <= end; i++) {
2254 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2255 res = random_generate(random);
2256 tmpbuf = bprintf("%s%d",random_id,i);
2257 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2262 XBT_INFO("Malformed radical");
2264 res = random_generate(random);
2265 rd_name = bprintf("%s_router",random_id);
2266 rd_value = bprintf("%f",res);
2267 xbt_dict_set(random_value, rd_name, rd_value, free);
2269 xbt_dynar_free(&radical_ends);
2272 xbt_dynar_free(&radical_elements);
2276 static void routing_parse_Erandom(void)
2278 xbt_dict_cursor_t cursor = NULL;
2282 xbt_dict_foreach(random_value, cursor, key, elem) {
2283 XBT_DEBUG("%s = %s",key,elem);
2290 * New methods to init the routing model component from the lua script
2294 * calling parse_S_AS_lua with lua values
2296 void routing_AS_init(const char *AS_id, const char *AS_routing)
2298 parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
2302 * calling parse_E_AS_lua to fisnish the creation of routing component
2304 void routing_AS_end(const char *AS_id)
2306 parse_E_AS_lua((char *) AS_id);
2310 * add a host to the network element list
2313 void routing_add_host(const char *host_id)
2315 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2319 * Set a new link on the actual list of link for a route or ASroute
2321 void routing_add_link(const char *link_id)
2323 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2327 *Set the endpoints for a route
2329 void routing_set_route(const char *src_id, const char *dst_id)
2331 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2335 * Store the route by calling parse_E_route_store_route
2337 void routing_store_route(void)
2339 parse_E_route_store_route();