1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <pcre.h> /* regular expression library */
8 #include "surf_routing_private.h"
9 #include "surf/surf_routing.h"
10 #include "surf/surfxml_parse_values.h"
13 int ROUTING_HOST_LEVEL; //Routing level
14 int SURF_CPU_LEVEL; //Surf cpu level
15 int SURF_WKS_LEVEL; //Surf workstation level
16 int SIMIX_HOST_LEVEL; //Simix level
17 int MSG_HOST_LEVEL; //Msg level
18 int SD_HOST_LEVEL; //Simdag level
19 int COORD_HOST_LEVEL; //Coordinates level
20 int NS3_HOST_LEVEL; //host node for ns3
23 int SD_LINK_LEVEL; //Simdag level
24 int SURF_LINK_LEVEL; //Surf level
25 int NS3_LINK_LEVEL; //link for ns3
27 xbt_lib_t as_router_lib;
28 int ROUTING_ASR_LEVEL; //Routing level
29 int COORD_ASR_LEVEL; //Coordinates level
30 int NS3_ASR_LEVEL; //host node for ns3
32 static xbt_dict_t patterns = NULL;
33 static xbt_dict_t random_value = NULL;
36 routing_global_t global_routing = NULL;
37 routing_component_t current_routing = NULL;
38 model_type_t current_routing_model = NULL;
40 /* global parse functions */
41 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
42 static const char *src = NULL; /* temporary store the source name of a route */
43 static const char *dst = NULL; /* temporary store the destination name of a route */
44 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
45 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
46 static double_f_cpvoid_t get_link_latency = NULL;
47 xbt_dict_t cluster_host_link = NULL; /* for tag cluster */
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_routing_after_parse(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},
93 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
94 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
95 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
96 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
97 {"Cluster", "Cluster routing", model_cluster_create,
98 model_cluster_load, model_cluster_unload, model_cluster_end},
99 {NULL, NULL, NULL, NULL, NULL, NULL}
102 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
104 double src_coord, dst_coord;
106 src_coord = atof(xbt_dynar_get_as(src, index, char *));
107 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
109 return (src_coord-dst_coord)*(src_coord-dst_coord);
113 static double base_vivaldi_get_latency (const char *src, const char *dst)
115 double euclidean_dist;
116 xbt_dynar_t src_ctn, dst_ctn;
117 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
118 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
119 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
120 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
122 if(dst_ctn == NULL || src_ctn == NULL)
123 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
125 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
126 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
128 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
131 return euclidean_dist / 1000;
134 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
136 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
137 int need_to_clean = e_route?0:1;
139 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
140 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
141 if(need_to_clean) generic_free_extended_route(e_route);
144 return base_vivaldi_get_latency(src,dst);
149 * \brief Add a "host" to the network element list
151 static void parse_S_host(const char *host_id, const char* coord)
153 network_element_info_t info = NULL;
154 if (current_routing->hierarchy == SURF_ROUTING_NULL)
155 current_routing->hierarchy = SURF_ROUTING_BASE;
156 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
157 "Reading a host, processing unit \"%s\" already exists",
159 xbt_assert(current_routing->set_processing_unit,
160 "no defined method \"set_processing_unit\" in \"%s\"",
161 current_routing->name);
162 (*(current_routing->set_processing_unit)) (current_routing, host_id);
163 info = xbt_new0(s_network_element_info_t, 1);
164 info->rc_component = current_routing;
165 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
166 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
167 if (strcmp(coord,"")) {
168 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
169 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
170 xbt_dynar_shrink(ctn, 0);
171 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
175 static void parse_E_host(void)
177 xbt_dict_cursor_t cursor = NULL;
181 xbt_dict_foreach(current_property_set, cursor, key, elem) {
182 XBT_DEBUG("property : %s = %s",key,elem);
187 * \brief Add a host to the network element list from XML
189 static void parse_S_host_XML(void)
191 // XBT_INFO("parse_S_host_XML");
192 // XBT_INFO("'%s' '%s'",struct_host->V_host_id, struct_host->V_host_coord);
193 parse_S_host(struct_host->V_host_id, struct_host->V_host_coord);
195 static void parse_E_host_XML(void)
201 * \brief Add a host to the network element list from lua script
203 static void parse_S_host_lua(const char *host_id, const char *coord)
205 parse_S_host(host_id, coord);
210 * \brief Add a "router" to the network element list
212 static void parse_S_router(void)
214 network_element_info_t info = NULL;
215 if (current_routing->hierarchy == SURF_ROUTING_NULL)
216 current_routing->hierarchy = SURF_ROUTING_BASE;
217 xbt_assert(!xbt_lib_get_or_null(as_router_lib,struct_router->V_router_id, ROUTING_ASR_LEVEL),
218 "Reading a router, processing unit \"%s\" already exists",
219 struct_router->V_router_id);
220 xbt_assert(current_routing->set_processing_unit,
221 "no defined method \"set_processing_unit\" in \"%s\"",
222 current_routing->name);
223 (*(current_routing->set_processing_unit)) (current_routing,
224 struct_router->V_router_id);
225 info = xbt_new0(s_network_element_info_t, 1);
226 info->rc_component = current_routing;
227 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
229 xbt_lib_set(as_router_lib,struct_router->V_router_id,ROUTING_ASR_LEVEL,(void *) info);
230 if (strcmp(A_surfxml_router_coordinates,"")) {
231 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
232 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
233 xbt_dynar_shrink(ctn, 0);
234 xbt_lib_set(as_router_lib,struct_router->V_router_id,COORD_ASR_LEVEL,(void *) ctn);
239 * brief Add a "router" to the network element list from XML description
241 static void parse_S_router_XML(void)
243 return parse_S_router();
247 * brief Add a "router" to the network element list from XML description
249 static void parse_S_router_lua(const char* router_id)
251 struct_router->V_router_id = xbt_strdup(router_id);
252 struct_router->V_router_coord = xbt_strdup("");
253 return parse_S_router();
257 * \brief Set the endponints for a route
259 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
261 if (src != NULL && dst != NULL && link_list != NULL)
262 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
266 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
267 "Some limits are null in the route between \"%s\" and \"%s\"",
269 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
273 * \brief Set the endpoints for a route from XML
275 static void parse_S_route_new_and_endpoints_XML(void)
277 parse_S_route_new_and_endpoints(A_surfxml_route_src,
278 A_surfxml_route_dst);
282 * \brief Set the endpoints for a route from lua
284 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
286 parse_S_route_new_and_endpoints(id_src, id_dst);
290 * \brief Set the endponints and gateways for a ASroute
292 static void parse_S_ASroute_new_and_endpoints(void)
294 if (src != NULL && dst != NULL && link_list != NULL)
295 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
296 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
297 src = A_surfxml_ASroute_src;
298 dst = A_surfxml_ASroute_dst;
299 gw_src = A_surfxml_ASroute_gw_src;
300 gw_dst = A_surfxml_ASroute_gw_dst;
301 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
302 || strlen(gw_dst) > 0,
303 "Some limits are null in the route between \"%s\" and \"%s\"",
305 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
309 * \brief Set the endponints for a bypassRoute
311 static void parse_S_bypassRoute_new_and_endpoints(void)
313 if (src != NULL && dst != NULL && link_list != NULL)
315 "Bypass Route between %s to %s can not be defined",
316 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
317 src = A_surfxml_bypassRoute_src;
318 dst = A_surfxml_bypassRoute_dst;
319 gw_src = A_surfxml_bypassRoute_gw_src;
320 gw_dst = A_surfxml_bypassRoute_gw_dst;
321 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
322 || strlen(gw_dst) > 0,
323 "Some limits are null in the route between \"%s\" and \"%s\"",
325 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
329 * \brief Set a new link on the actual list of link for a route or ASroute
331 static void parse_E_link_ctn_new_elem(const char *link_id)
334 val = xbt_strdup(link_id);
335 xbt_dynar_push(link_list, &val);
339 * \brief Set a new link on the actual list of link for a route or ASroute from XML
342 static void parse_E_link_ctn_new_elem_XML(void)
344 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
345 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
346 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
347 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
348 parse_E_link_ctn_new_elem(link_id);
351 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
352 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
353 parse_E_link_ctn_new_elem(link_id);
359 * \brief Set a new link on the actual list of link for a route or ASroute from lua
361 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
363 parse_E_link_ctn_new_elem(link_id);
367 * \brief Store the route by calling the set_route function of the current routing component
369 static void parse_E_route_store_route(void)
371 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
372 route->generic_route.link_list = link_list;
373 xbt_assert(current_routing->set_route,
374 "no defined method \"set_route\" in \"%s\"",
375 current_routing->name);
376 (*(current_routing->set_route)) (current_routing, src, dst, route);
383 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
385 static void parse_E_ASroute_store_route(void)
387 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
388 e_route->generic_route.link_list = link_list;
389 e_route->src_gateway = xbt_strdup(gw_src);
390 e_route->dst_gateway = xbt_strdup(gw_dst);
391 xbt_assert(current_routing->set_ASroute,
392 "no defined method \"set_ASroute\" in \"%s\"",
393 current_routing->name);
394 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
403 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
405 static void parse_E_bypassRoute_store_route(void)
407 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
408 e_route->generic_route.link_list = link_list;
409 e_route->src_gateway = xbt_strdup(gw_src);
410 e_route->dst_gateway = xbt_strdup(gw_dst);
411 xbt_assert(current_routing->set_bypassroute,
412 "no defined method \"set_bypassroute\" in \"%s\"",
413 current_routing->name);
414 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
424 * \brief Make a new routing component
426 * make the new structure and
427 * set the parsing functions to allows parsing the part of the routing tree
429 void routing_AS_init(const char *AS_id, const char *wanted_routing_type)
431 routing_component_t new_routing;
432 model_type_t model = NULL;
434 /* search the routing model */
435 for (cpt = 0; routing_models[cpt].name; cpt++)
436 if (!strcmp(wanted_routing_type, routing_models[cpt].name))
437 model = &routing_models[cpt];
438 /* if its not exist, error */
440 fprintf(stderr, "Routing model %s not found. Existing models:\n",
441 wanted_routing_type);
442 for (cpt = 0; routing_models[cpt].name; cpt++)
443 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
444 routing_models[cpt].desc);
448 /* make a new routing component */
449 new_routing = (routing_component_t) (*(model->create)) ();
450 new_routing->routing = model;
451 new_routing->hierarchy = SURF_ROUTING_NULL;
452 new_routing->name = xbt_strdup(AS_id);
453 new_routing->routing_sons = xbt_dict_new();
455 /* Hack for Vivaldi */
456 if(!strcmp(model->name,"Vivaldi"))
457 new_routing->get_latency = vivaldi_get_link_latency;
459 if (current_routing == NULL && global_routing->root == NULL) {
461 /* it is the first one */
462 new_routing->routing_father = NULL;
463 global_routing->root = new_routing;
465 } else if (current_routing != NULL && global_routing->root != NULL) {
467 xbt_assert(!xbt_dict_get_or_null
468 (current_routing->routing_sons, AS_id),
469 "The AS \"%s\" already exists", AS_id);
470 /* it is a part of the tree */
471 new_routing->routing_father = current_routing;
472 /* set the father behavior */
473 if (current_routing->hierarchy == SURF_ROUTING_NULL)
474 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
475 /* add to the sons dictionary */
476 xbt_dict_set(current_routing->routing_sons, AS_id,
477 (void *) new_routing, NULL);
478 /* add to the father element list */
479 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
480 /* unload the prev parse rules */
481 (*(current_routing->routing->unload)) ();
484 THROWF(arg_error, 0, "All defined components must be belong to a AS");
486 /* set the new parse rules */
487 (*(new_routing->routing->load)) ();
488 /* set the new current component of the tree */
489 current_routing = new_routing;
493 * Detect the routing model type of the routing component from XML platforms
495 static void parse_S_AS(void)
497 routing_AS_init(A_surfxml_AS_id, A_surfxml_AS_routing);
502 * \brief Finish the creation of a new routing component
504 * When you finish to read the routing component, other structures must be created.
505 * the "end" method allow to do that for any routing model type
507 void routing_AS_end(const char *AS_id)
510 if (current_routing == NULL) {
511 THROWF(arg_error, 0, "Close AS(%s), that were never opened", AS_id);
513 network_element_info_t info = NULL;
514 xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
515 "The AS \"%s\" already exists",current_routing->name);
516 info = xbt_new0(s_network_element_info_t, 1);
517 info->rc_component = current_routing->routing_father;
518 info->rc_type = SURF_NETWORK_ELEMENT_AS;
519 xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
521 (*(current_routing->routing->unload)) ();
522 (*(current_routing->routing->end)) ();
523 current_routing = current_routing->routing_father;
524 if (current_routing != NULL)
525 (*(current_routing->routing->load)) ();
530 * \brief Finish the creation of a new routing component from XML
532 static void parse_E_AS(void)
534 routing_AS_end(A_surfxml_AS_id);
537 /* Aux Business methods */
540 * \brief Get the AS name of the element
542 * \param name the host name
545 static char* elements_As_name(const char *name)
547 routing_component_t as_comp;
549 /* (1) find the as where the host is located */
550 as_comp = ((network_element_info_t)
551 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
552 return as_comp->name;
557 * \brief Get the AS father and the first elements of the chain
559 * \param src the source host name
560 * \param dst the destination host name
562 * Get the common father of the to processing units, and the first different
563 * father in the chain
565 static void elements_father(const char *src, const char *dst,
566 routing_component_t *res_father,
567 routing_component_t *res_src,
568 routing_component_t *res_dst)
570 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
571 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
572 routing_component_t src_as, dst_as;
573 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
574 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
577 routing_component_t current;
578 routing_component_t current_src;
579 routing_component_t current_dst;
580 routing_component_t father;
582 /* (1) find the as where the src and dst are located */
583 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
585 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
588 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
590 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
591 src_as = src_data->rc_component;
592 dst_as = dst_data->rc_component;
594 xbt_assert(src_as && dst_as,
595 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
597 /* (2) find the path to the root routing component */
598 for (current = src_as ; current != NULL ; current = current->routing_father) {
599 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
600 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
601 path_src[index_src++] = current;
603 for (current = dst_as ; current != NULL ; current = current->routing_father) {
604 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
605 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
606 path_dst[index_dst++] = current;
609 /* (3) find the common father */
611 current_src = path_src[--index_src];
612 current_dst = path_dst[--index_dst];
613 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
615 /* (4) they are not in the same routing component, make the path */
616 if (current_src == current_dst)
617 father = current_src;
619 father = path_src[index_src + 1];
621 /* (5) result generation */
622 *res_father = father; /* first the common father of src and dst */
623 *res_src = current_src; /* second the first different father of src */
624 *res_dst = current_dst; /* three the first different father of dst */
626 #undef ELEMENTS_FATHER_MAXDEPTH
629 /* Global Business methods */
632 * \brief Recursive function for get_route_latency
634 * \param src the source host name
635 * \param dst the destination host name
636 * \param *e_route the route where the links are stored
637 * \param *latency the latency, if needed
639 * This function is called by "get_route" and "get_latency". It allows to walk
640 * recursively through the routing components tree.
642 static void _get_route_latency(const char *src, const char *dst,
643 xbt_dynar_t *route, double *latency)
645 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
646 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
648 routing_component_t common_father;
649 routing_component_t src_father;
650 routing_component_t dst_father;
651 elements_father(src, dst, &common_father, &src_father, &dst_father);
653 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
655 route_extended_t e_route = NULL;
657 e_route = common_father->get_route(common_father, src, dst);
658 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
659 *route = e_route->generic_route.link_list;
662 *latency = common_father->get_latency(common_father, src, dst, e_route);
663 xbt_assert(*latency >= 0.0,
664 "latency error on route between \"%s\" and \"%s\"", src, dst);
667 xbt_free(e_route->src_gateway);
668 xbt_free(e_route->dst_gateway);
672 } else { /* SURF_ROUTING_RECURSIVE */
674 route_extended_t e_route_bypass = NULL;
675 if (common_father->get_bypass_route)
676 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
678 xbt_assert(!latency || !e_route_bypass,
679 "Bypass cannot work yet with get_latency");
681 route_extended_t e_route_cnt = e_route_bypass
683 : common_father->get_route(common_father,
684 src_father->name, dst_father->name);
686 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
687 src_father->name, dst_father->name);
689 xbt_assert((e_route_cnt->src_gateway == NULL) ==
690 (e_route_cnt->dst_gateway == NULL),
691 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
694 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
697 *latency = common_father->get_latency(common_father,
698 src_father->name, dst_father->name,
700 xbt_assert(*latency >= 0.0,
701 "latency error on route between \"%s\" and \"%s\"",
702 src_father->name, dst_father->name);
708 if (strcmp(src, e_route_cnt->src_gateway)) {
710 xbt_dynar_t route_src;
712 _get_route_latency(src, e_route_cnt->src_gateway,
713 (route ? &route_src : NULL),
714 (latency ? &latency_src : NULL));
716 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
717 src, e_route_cnt->src_gateway);
718 xbt_dynar_foreach(route_src, cpt, link) {
719 xbt_dynar_push(*route, &link);
721 xbt_dynar_free(&route_src);
724 xbt_assert(latency_src >= 0.0,
725 "latency error on route between \"%s\" and \"%s\"",
726 src, e_route_cnt->src_gateway);
727 *latency += latency_src;
732 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
733 xbt_dynar_push(*route, &link);
737 if (strcmp(e_route_cnt->dst_gateway, dst)) {
739 xbt_dynar_t route_dst;
741 _get_route_latency(e_route_cnt->dst_gateway, dst,
742 (route ? &route_dst : NULL),
743 (latency ? &latency_dst : NULL));
745 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
746 e_route_cnt->dst_gateway, dst);
747 xbt_dynar_foreach(route_dst, cpt, link) {
748 xbt_dynar_push(*route, &link);
750 xbt_dynar_free(&route_dst);
753 xbt_assert(latency_dst >= 0.0,
754 "latency error on route between \"%s\" and \"%s\"",
755 e_route_cnt->dst_gateway, dst);
756 *latency += latency_dst;
760 generic_free_extended_route(e_route_cnt);
765 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
767 static void get_route_latency(const char *src, const char *dst,
768 xbt_dynar_t *route, double *latency, int cleanup)
770 _get_route_latency(src, dst, route, latency);
771 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
772 xbt_assert(!latency || *latency >= 0.0,
773 "latency error on route between \"%s\" and \"%s\"", src, dst);
775 xbt_dynar_free(&global_routing->last_route);
776 global_routing->last_route = cleanup ? *route : NULL;
781 * \brief Generic method: find a route between hosts
783 * \param src the source host name
784 * \param dst the destination host name
786 * walk through the routing components tree and find a route between hosts
787 * by calling the differents "get_route" functions in each routing component.
788 * No need to free the returned dynar. It will be freed at the next call.
790 static xbt_dynar_t get_route(const char *src, const char *dst)
792 xbt_dynar_t route = NULL;
793 get_route_latency(src, dst, &route, NULL, 1);
798 * \brief Generic method: find a route between hosts
800 * \param src the source host name
801 * \param dst the destination host name
803 * same as get_route, but return NULL if any exception is raised.
805 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
807 xbt_dynar_t route = NULL;
810 get_route_latency(src, dst, &route, NULL, 1);
812 xbt_ex_free(exception);
819 * \brief Generic method: find a route between hosts
821 * \param src the source host name
822 * \param dst the destination host name
824 * walk through the routing components tree and find a route between hosts
825 * by calling the differents "get_route" functions in each routing component.
826 * Leaves the caller the responsability to clean the returned dynar.
828 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
830 xbt_dynar_t route = NULL;
831 get_route_latency(src, dst, &route, NULL, 0);
836 static double get_latency(const char *src, const char *dst)
838 double latency = -1.0;
839 get_route_latency(src, dst, NULL, &latency, 0);
843 static int surf_parse_models_setup_already_called=0;
844 /* Call the last initialization functions, that must be called after the
845 * <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
847 void surf_parse_models_setup()
849 if (surf_parse_models_setup_already_called)
851 surf_parse_models_setup_already_called=1;
852 routing_parse_Erandom();
853 surf_config_models_setup();
858 * \brief Recursive function for finalize
860 * \param rc the source host name
862 * This fuction is call by "finalize". It allow to finalize the
863 * AS or routing components. It delete all the structures.
865 static void _finalize(routing_component_t rc)
868 xbt_dict_cursor_t cursor = NULL;
870 routing_component_t elem;
871 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
874 xbt_dict_t tmp_sons = rc->routing_sons;
875 char *tmp_name = rc->name;
876 xbt_dict_free(&tmp_sons);
878 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
879 current_routing->name);
880 (*(rc->finalize)) (rc);
885 * \brief Generic method: delete all the routing structures
887 * walk through the routing components tree and delete the structures
888 * by calling the differents "finalize" functions in each routing component
890 static void finalize(void)
892 /* delete recursibly all the tree */
893 _finalize(global_routing->root);
894 /* delete last_route */
895 xbt_dynar_free(&(global_routing->last_route));
896 /* delete global routing structure */
897 xbt_free(global_routing);
898 /* make sure that we will reinit the models while loading the platf once reinited -- HACK but there is no proper surf_routing_init() */
899 surf_parse_models_setup_already_called = 0;
902 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
904 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
906 //adding my one link routes
909 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
911 xbt_dynar_foreach(onelink_mine, cpt, link) {
912 xbt_dynar_push(ret, &link);
917 xbt_dict_cursor_t cursor = NULL;
918 routing_component_t rc_child;
919 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
920 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
922 xbt_dynar_foreach(onelink_child, cpt, link) {
923 xbt_dynar_push(ret, &link);
930 static xbt_dynar_t get_onelink_routes(void)
932 return recursive_get_onelink_routes(global_routing->root);
935 e_surf_network_element_type_t get_network_element_type(const char
938 network_element_info_t rc = NULL;
940 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
941 if(rc) return rc->rc_type;
943 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
944 if(rc) return rc->rc_type;
946 return SURF_NETWORK_ELEMENT_NULL;
950 * \brief Generic method: create the global routing schema
952 * Make a global routing structure and set all the parsing functions.
954 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
956 /* config the uniq global routing */
957 global_routing = xbt_new0(s_routing_global_t, 1);
958 global_routing->root = NULL;
959 global_routing->get_route = get_route;
960 global_routing->get_route_or_null = get_route_or_null;
961 global_routing->get_latency = get_latency;
962 global_routing->get_route_no_cleanup = get_route_no_cleanup;
963 global_routing->get_onelink_routes = get_onelink_routes;
964 global_routing->get_route_latency = get_route_latency;
965 global_routing->get_network_element_type = get_network_element_type;
966 global_routing->finalize = finalize;
967 global_routing->loopback = loopback;
968 global_routing->size_of_link = size_of_links;
969 global_routing->last_route = NULL;
970 get_link_latency = get_link_latency_fun;
971 /* no current routing at moment */
972 current_routing = NULL;
974 /* parse generic elements */
975 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
976 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
977 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
979 surfxml_add_callback(STag_surfxml_route_cb_list,
980 &parse_S_route_new_and_endpoints_XML);
981 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
982 &parse_S_ASroute_new_and_endpoints);
983 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
984 &parse_S_bypassRoute_new_and_endpoints);
986 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
987 &parse_E_link_ctn_new_elem_XML);
989 surfxml_add_callback(ETag_surfxml_route_cb_list,
990 &parse_E_route_store_route);
991 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
992 &parse_E_ASroute_store_route);
993 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
994 &parse_E_bypassRoute_store_route);
996 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS);
997 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS);
999 surfxml_add_callback(STag_surfxml_cluster_cb_list,
1000 &routing_parse_Scluster);
1002 surfxml_add_callback(STag_surfxml_peer_cb_list,
1003 &routing_parse_Speer);
1005 surfxml_add_callback(ETag_surfxml_platform_cb_list,
1006 &clean_routing_after_parse);
1009 instr_routing_define_callbacks();
1013 void surf_parse_add_callback_config(void)
1015 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1016 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1017 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1018 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1021 /* ************************************************** */
1022 /* ********** PATERN FOR NEW ROUTING **************** */
1024 /* The minimal configuration of a new routing model need the next functions,
1025 * also you need to set at the start of the file, the new model in the model
1026 * list. Remember keep the null ending of the list.
1028 /*** Routing model structure ***/
1030 // s_routing_component_t generic_routing;
1031 // /* things that your routing model need */
1032 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1034 /*** Parse routing model functions ***/
1035 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1036 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1037 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1038 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1039 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1041 /*** Business methods ***/
1042 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1043 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1044 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1046 /*** Creation routing model functions ***/
1047 // static void* model_NEW_create(void) {
1048 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1049 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1050 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1051 // new_component->generic_routing.set_route = model_NEW_set_route;
1052 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1053 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1054 // new_component->generic_routing.get_route = NEW_get_route;
1055 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1056 // new_component->generic_routing.finalize = NEW_finalize;
1057 // /* initialization of internal structures */
1058 // return new_component;
1059 // } /* mandatory */
1060 // static void model_NEW_load(void) {} /* mandatory */
1061 // static void model_NEW_unload(void) {} /* mandatory */
1062 // static void model_NEW_end(void) {} /* mandatory */
1064 /* ************************************************************************** */
1065 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1067 void generic_set_processing_unit(routing_component_t rc,
1070 XBT_DEBUG("Load process unit \"%s\"", name);
1071 int *id = xbt_new0(int, 1);
1072 xbt_dict_t _to_index;
1073 _to_index = current_routing->to_index;
1074 *id = xbt_dict_length(_to_index);
1075 xbt_dict_set(_to_index, name, id, xbt_free);
1078 void generic_set_autonomous_system(routing_component_t rc,
1081 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1082 int *id = xbt_new0(int, 1);
1083 xbt_dict_t _to_index;
1084 _to_index = current_routing->to_index;
1085 *id = xbt_dict_length(_to_index);
1086 xbt_dict_set(_to_index, name, id, xbt_free);
1089 int surf_pointer_resource_cmp(const void *a, const void *b)
1094 int surf_link_resource_cmp(const void *a, const void *b)
1096 return !!memcmp(a,b,global_routing->size_of_link);
1099 void generic_set_bypassroute(routing_component_t rc,
1100 const char *src, const char *dst,
1101 route_extended_t e_route)
1103 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1104 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1107 route_name = bprintf("%s#%s", src, dst);
1108 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1109 "Invalid count of links, must be greater than zero (%s,%s)",
1111 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1112 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1113 src, e_route->src_gateway, dst, e_route->dst_gateway);
1115 route_extended_t new_e_route =
1116 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1117 xbt_dynar_free(&(e_route->generic_route.link_list));
1120 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1121 (void (*)(void *)) generic_free_extended_route);
1122 xbt_free(route_name);
1125 /* ************************************************************************** */
1126 /* *********************** GENERIC BUSINESS METHODS ************************* */
1128 double generic_get_link_latency(routing_component_t rc,
1129 const char *src, const char *dst,
1130 route_extended_t route)
1132 int need_to_clean = route?0:1;
1135 double latency = 0.0;
1137 route = route?route:rc->get_route(rc,src,dst);
1139 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1140 latency += get_link_latency(link);
1142 if(need_to_clean) generic_free_extended_route(route);
1146 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1148 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1151 route_extended_t generic_get_bypassroute(routing_component_t rc,
1155 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1156 routing_component_t src_as, dst_as;
1157 int index_src, index_dst;
1158 xbt_dynar_t path_src = NULL;
1159 xbt_dynar_t path_dst = NULL;
1160 routing_component_t current = NULL;
1161 routing_component_t *current_src = NULL;
1162 routing_component_t *current_dst = NULL;
1164 /* (1) find the as where the src and dst are located */
1165 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1166 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1167 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1168 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1170 if(src_data == NULL || dst_data == NULL)
1171 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1172 src, dst, rc->name);
1174 src_as = ((network_element_info_t)src_data)->rc_component;
1175 dst_as = ((network_element_info_t)dst_data)->rc_component;
1177 /* (2) find the path to the root routing component */
1178 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1180 while (current != NULL) {
1181 xbt_dynar_push(path_src, ¤t);
1182 current = current->routing_father;
1184 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1186 while (current != NULL) {
1187 xbt_dynar_push(path_dst, ¤t);
1188 current = current->routing_father;
1191 /* (3) find the common father */
1192 index_src = path_src->used - 1;
1193 index_dst = path_dst->used - 1;
1194 current_src = xbt_dynar_get_ptr(path_src, index_src);
1195 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1196 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1197 xbt_dynar_pop_ptr(path_src);
1198 xbt_dynar_pop_ptr(path_dst);
1201 current_src = xbt_dynar_get_ptr(path_src, index_src);
1202 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1205 int max_index_src = path_src->used - 1;
1206 int max_index_dst = path_dst->used - 1;
1208 int max_index = max(max_index_src, max_index_dst);
1211 route_extended_t e_route_bypass = NULL;
1213 for (max = 0; max <= max_index; max++) {
1214 for (i = 0; i < max; i++) {
1215 if (i <= max_index_src && max <= max_index_dst) {
1216 char *route_name = bprintf("%s#%s",
1217 (*(routing_component_t *)
1219 (path_src, i)))->name,
1220 (*(routing_component_t *)
1222 (path_dst, max)))->name);
1224 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1225 xbt_free(route_name);
1229 if (max <= max_index_src && i <= max_index_dst) {
1230 char *route_name = bprintf("%s#%s",
1231 (*(routing_component_t *)
1233 (path_src, max)))->name,
1234 (*(routing_component_t *)
1236 (path_dst, i)))->name);
1238 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1239 xbt_free(route_name);
1248 if (max <= max_index_src && max <= max_index_dst) {
1249 char *route_name = bprintf("%s#%s",
1250 (*(routing_component_t *)
1252 (path_src, max)))->name,
1253 (*(routing_component_t *)
1255 (path_dst, max)))->name);
1256 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1257 xbt_free(route_name);
1263 xbt_dynar_free(&path_src);
1264 xbt_dynar_free(&path_dst);
1266 route_extended_t new_e_route = NULL;
1268 if (e_route_bypass) {
1270 unsigned int cpt = 0;
1271 new_e_route = xbt_new0(s_route_extended_t, 1);
1272 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1273 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1274 new_e_route->generic_route.link_list =
1275 xbt_dynar_new(global_routing->size_of_link, NULL);
1276 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1277 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1284 /* ************************************************************************** */
1285 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1288 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1289 void *data, int order)
1295 xbt_dynar_t links = NULL, links_id = NULL;
1297 new_route = xbt_new0(s_route_t, 1);
1298 new_route->link_list =
1299 xbt_dynar_new(global_routing->size_of_link, NULL);
1301 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1302 "the hierarchy type is not SURF_ROUTING_BASE");
1304 links = ((route_t) data)->link_list;
1307 links_id = new_route->link_list;
1309 xbt_dynar_foreach(links, cpt, link_name) {
1312 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1315 xbt_dynar_push(links_id, &link);
1317 xbt_dynar_unshift(links_id, &link);
1319 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1326 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1327 void *data, int order)
1331 route_extended_t e_route, new_e_route;
1334 xbt_dynar_t links = NULL, links_id = NULL;
1336 new_e_route = xbt_new0(s_route_extended_t, 1);
1337 new_e_route->generic_route.link_list =
1338 xbt_dynar_new(global_routing->size_of_link, NULL);
1339 new_e_route->src_gateway = NULL;
1340 new_e_route->dst_gateway = NULL;
1342 xbt_assert(hierarchy == SURF_ROUTING_BASE
1343 || hierarchy == SURF_ROUTING_RECURSIVE,
1344 "the hierarchy type is not defined");
1346 if (hierarchy == SURF_ROUTING_BASE) {
1348 route = (route_t) data;
1349 links = route->link_list;
1351 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1353 e_route = (route_extended_t) data;
1354 xbt_assert(e_route->src_gateway
1355 && e_route->dst_gateway, "bad gateway, is null");
1356 links = e_route->generic_route.link_list;
1358 /* remeber not erase the gateway names */
1359 new_e_route->src_gateway = strdup(e_route->src_gateway);
1360 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1363 links_id = new_e_route->generic_route.link_list;
1365 xbt_dynar_foreach(links, cpt, link_name) {
1368 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1371 xbt_dynar_push(links_id, &link);
1373 xbt_dynar_unshift(links_id, &link);
1375 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1381 void generic_free_route(route_t route)
1384 xbt_dynar_free(&(route->link_list));
1389 void generic_free_extended_route(route_extended_t e_route)
1392 xbt_dynar_free(&(e_route->generic_route.link_list));
1393 if (e_route->src_gateway)
1394 xbt_free(e_route->src_gateway);
1395 if (e_route->dst_gateway)
1396 xbt_free(e_route->dst_gateway);
1401 static routing_component_t generic_as_exist(routing_component_t find_from,
1402 routing_component_t to_find)
1404 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1405 xbt_dict_cursor_t cursor = NULL;
1408 routing_component_t elem;
1409 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1410 if (to_find == elem || generic_as_exist(elem, to_find)) {
1421 generic_autonomous_system_exist(routing_component_t rc, char *element)
1423 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1424 routing_component_t element_as, result, elem;
1425 xbt_dict_cursor_t cursor = NULL;
1427 element_as = ((network_element_info_t)
1428 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1429 result = ((routing_component_t) - 1);
1430 if (element_as != rc)
1431 result = generic_as_exist(rc, element_as);
1435 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1436 found = !strcmp(elem->name, element);
1447 generic_processing_units_exist(routing_component_t rc, char *element)
1449 routing_component_t element_as;
1450 element_as = ((network_element_info_t)
1451 xbt_lib_get_or_null(host_lib,
1452 element, ROUTING_HOST_LEVEL))->rc_component;
1453 if (element_as == rc)
1455 return generic_as_exist(rc, element_as);
1458 void generic_src_dst_check(routing_component_t rc, const char *src,
1462 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1463 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1464 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1465 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1467 if(src_data == NULL || dst_data == NULL)
1468 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1469 src, dst, rc->name);
1471 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1472 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1474 if(src_as != dst_as)
1475 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1476 src, src_as->name, dst, dst_as->name);
1478 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1479 src,dst,src_as->name, dst_as->name,rc->name);
1482 static void routing_parse_Sconfig(void)
1484 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1487 static void routing_parse_Econfig(void)
1489 xbt_dict_cursor_t cursor = NULL;
1493 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1494 cfg = bprintf("%s:%s",key,elem);
1495 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1496 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1498 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
1501 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1504 void routing_parse_Scluster(void)
1506 if(!cluster_host_link)
1507 cluster_host_link = xbt_dict_new();
1509 static int AX_ptr = 0;
1510 char *host_id, *groups, *link_id = NULL;
1511 char *availability_file = xbt_strdup(A_surfxml_cluster_availability_file);
1512 char *state_file = xbt_strdup(A_surfxml_cluster_state_file);
1514 if(xbt_dict_size(patterns)==0)
1515 patterns = xbt_dict_new();
1517 xbt_dict_set(patterns,"id",struct_cluster->V_cluster_id,NULL);
1518 xbt_dict_set(patterns,"prefix",struct_cluster->V_cluster_prefix,NULL);
1519 xbt_dict_set(patterns,"suffix",struct_cluster->V_cluster_suffix,NULL);
1521 char *route_src_dst;
1524 xbt_dynar_t radical_elements;
1525 xbt_dynar_t radical_ends;
1526 int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
1527 int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
1528 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1529 xbt_dict_set(cluster_host_link,struct_cluster->V_cluster_id,bprintf("fullduplex"),free);
1531 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1532 static unsigned int surfxml_buffer_stack_stack[1024];
1534 surfxml_buffer_stack_stack[0] = 0;
1536 surfxml_bufferstack_push(1);
1538 SURFXML_BUFFER_SET(AS_id, struct_cluster->V_cluster_id);
1539 SURFXML_BUFFER_SET(AS_routing, "Cluster");
1540 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", struct_cluster->V_cluster_id);
1541 SURFXML_START_TAG(AS);
1543 radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ",");
1544 xbt_dynar_foreach(radical_elements, iter, groups) {
1545 radical_ends = xbt_str_split(groups, "-");
1546 switch (xbt_dynar_length(radical_ends)) {
1548 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
1549 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, start, struct_cluster->V_cluster_suffix);
1550 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start);
1551 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1553 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1554 struct_host = xbt_new0(s_hostSG_t, 1);
1555 struct_host->V_host_id = host_id;
1556 if(!strcmp(A_surfxml_cluster_availability_file,"")){
1557 char* tmp_availability_file = xbt_strdup(availability_file);
1558 xbt_str_varsubst(tmp_availability_file,patterns);
1559 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1560 struct_host->V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1561 xbt_free(tmp_availability_file);
1565 XBT_DEBUG("\tavailability_file=\"\"");
1567 if(!strcmp(A_surfxml_cluster_state_file,"")){
1568 char *tmp_state_file = xbt_strdup(state_file);
1569 xbt_str_varsubst(tmp_state_file,patterns);
1570 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1571 struct_host->V_host_state_trace = tmgr_trace_new(tmp_state_file);
1572 xbt_free(tmp_state_file);
1576 XBT_DEBUG("\tstate_file=\"\"");
1579 struct_host->V_host_power_peak = struct_cluster->S_cluster_power;
1580 struct_host->V_host_power_scale = 1.0;
1581 struct_host->V_host_core = struct_cluster->S_cluster_core;
1582 struct_host->V_host_state_initial = SURF_RESOURCE_ON;
1583 struct_host->V_host_coord = "";
1584 STag_surfxml_host_cluster();
1585 XBT_DEBUG("</host>");
1587 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1588 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1589 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1590 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1591 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1593 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1595 struct_lnk = xbt_new0(s_link_t, 1);
1596 struct_lnk->V_link_id = link_id;
1597 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1598 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1599 struct_lnk->V_link_bandwidth_file = NULL;
1600 struct_lnk->V_link_latency_file = NULL;
1601 struct_lnk->V_link_state_file = NULL;
1602 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1603 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1605 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1606 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1609 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1610 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1611 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1612 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1614 STag_surfxml_link_cluster();
1616 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1617 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1618 ETag_surfxml_host();
1619 xbt_free(struct_host->V_host_id);
1620 struct_host->V_host_power_peak = 0.0;
1621 struct_host->V_host_core = 0;
1622 struct_host->V_host_power_scale = 0.0;
1623 struct_host->V_host_state_initial = SURF_RESOURCE_ON;
1624 struct_host->V_host_power_trace = NULL;
1625 struct_host->V_host_state_trace = NULL;
1626 xbt_free(struct_host->V_host_coord);
1627 xbt_free(struct_host);
1629 ETag_surfxml_link();
1630 xbt_free(struct_lnk->V_link_id);
1631 struct_lnk->V_link_bandwidth = 0;
1632 struct_lnk->V_link_bandwidth_file = NULL;
1633 struct_lnk->V_link_latency = 0;
1634 struct_lnk->V_link_latency_file = NULL;
1635 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1636 struct_lnk->V_link_state_file = NULL;
1637 struct_lnk->V_link_sharing_policy = 0;
1638 xbt_free(struct_lnk);
1644 surf_parse_get_int(&start,
1645 xbt_dynar_get_as(radical_ends, 0, char *));
1646 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1647 for (i = start; i <= end; i++) {
1648 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1649 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1650 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1651 A_surfxml_host_state = A_surfxml_host_state_ON;
1653 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1654 struct_host = xbt_new0(s_hostSG_t, 1);
1655 struct_host->V_host_id = host_id;
1656 if(!strcmp(A_surfxml_cluster_availability_file,"")){
1657 char* tmp_availability_file = xbt_strdup(availability_file);
1658 xbt_str_varsubst(tmp_availability_file,patterns);
1659 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1660 struct_host->V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1661 xbt_free(tmp_availability_file);
1665 XBT_DEBUG("\tavailability_file=\"\"");
1667 if(!strcmp(A_surfxml_cluster_state_file,"")){
1668 char *tmp_state_file = xbt_strdup(state_file);
1669 xbt_str_varsubst(tmp_state_file,patterns);
1670 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1671 struct_host->V_host_state_trace = tmgr_trace_new(tmp_state_file);
1672 xbt_free(tmp_state_file);
1676 XBT_DEBUG("\tstate_file=\"\"");
1679 struct_host->V_host_power_peak = struct_cluster->S_cluster_power;
1680 struct_host->V_host_power_scale = 1.0;
1681 struct_host->V_host_core = struct_cluster->S_cluster_core;
1682 struct_host->V_host_state_initial = SURF_RESOURCE_ON;
1683 struct_host->V_host_coord = xbt_strdup("");
1684 STag_surfxml_host_cluster();
1685 XBT_DEBUG("</host>");
1687 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1688 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1689 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1690 if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1691 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1693 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1695 struct_lnk = xbt_new0(s_link_t, 1);
1696 struct_lnk->V_link_id = link_id;
1697 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1698 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1699 struct_lnk->V_link_bandwidth_file = NULL;
1700 struct_lnk->V_link_latency_file = NULL;
1701 struct_lnk->V_link_state_file = NULL;
1702 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1703 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1705 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1706 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1709 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1710 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1711 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1712 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1714 STag_surfxml_link_cluster();
1716 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1717 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1719 ETag_surfxml_host();
1720 xbt_free(struct_host->V_host_id);
1721 struct_host->V_host_power_peak = 0.0;
1722 struct_host->V_host_core = 0;
1723 struct_host->V_host_power_scale = 0.0;
1724 struct_host->V_host_state_initial = SURF_RESOURCE_ON;
1725 struct_host->V_host_power_trace = NULL;
1726 struct_host->V_host_state_trace = NULL;
1727 xbt_free(struct_host->V_host_coord);
1728 xbt_free(struct_host);
1730 ETag_surfxml_link();
1731 xbt_free(struct_lnk->V_link_id);
1732 struct_lnk->V_link_bandwidth = 0;
1733 struct_lnk->V_link_bandwidth_file = NULL;
1734 struct_lnk->V_link_latency = 0;
1735 struct_lnk->V_link_latency_file = NULL;
1736 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1737 struct_lnk->V_link_state_file = NULL;
1738 struct_lnk->V_link_sharing_policy = 0;
1739 xbt_free(struct_lnk);
1744 XBT_DEBUG("Malformed radical");
1748 xbt_dynar_free(&radical_ends);
1750 xbt_dynar_free(&radical_elements);
1753 XBT_DEBUG("<router id=\"%s\"/>", struct_cluster->S_cluster_router_id);
1754 SURFXML_BUFFER_SET(router_id, struct_cluster->S_cluster_router_id);
1755 SURFXML_BUFFER_SET(router_coordinates, "");
1756 SURFXML_START_TAG(router);
1757 SURFXML_END_TAG(router);
1759 if( (struct_cluster->S_cluster_bb_bw!= 0) && (struct_cluster->S_cluster_bb_lat!=0) ){
1760 char *link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1761 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,struct_cluster->S_cluster_bb_bw, struct_cluster->S_cluster_bb_lat);
1763 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1764 if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1765 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1767 struct_lnk = xbt_new0(s_link_t, 1);
1768 struct_lnk->V_link_id = link_backbone;
1769 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bb_bw;
1770 struct_lnk->V_link_latency = struct_cluster->S_cluster_bb_lat;
1771 struct_lnk->V_link_bandwidth_file = NULL;
1772 struct_lnk->V_link_latency_file = NULL;
1773 struct_lnk->V_link_state_file = NULL;
1774 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1775 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1777 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1778 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1781 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1782 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1783 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1784 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1787 STag_surfxml_link_cluster();
1788 ETag_surfxml_link();
1789 free(link_backbone);
1794 char *new_suffix = xbt_strdup("");
1796 radical_elements = xbt_str_split(struct_cluster->V_cluster_suffix, ".");
1797 xbt_dynar_foreach(radical_elements, iter, groups) {
1798 if (strcmp(groups, "")) {
1799 char *old_suffix = new_suffix;
1800 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1805 xbt_dynar_free(&radical_elements);
1806 xbt_free(new_suffix);
1807 xbt_free(availability_file);
1808 xbt_free(state_file);
1810 xbt_dict_free(&patterns);
1813 SURFXML_END_TAG(AS);
1816 surfxml_bufferstack_pop(1);
1818 // xbt_dict_cursor_t cursor = NULL;
1822 // xbt_dict_foreach(cluster_host_link,cursor,key,data){
1823 // XBT_INFO("%s : %s",key,data);
1827 * This function take a string and replace parameters from patterns dict.
1828 * It returns the new value.
1830 static char* replace_random_parameter(char * string)
1832 char *test_string = NULL;
1834 if(xbt_dict_size(random_value)==0)
1837 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1838 test_string = bprintf("${%s}", string);
1839 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1841 if (strcmp(test_string,"")) { //if not empty, keep this value.
1843 string = test_string;
1844 } //In other case take old value (without ${})
1850 static void clean_routing_after_parse(void)
1852 xbt_dict_free(&random_value);
1853 xbt_dict_free(&patterns);
1856 static void routing_parse_Speer(void)
1858 static int AX_ptr = 0;
1859 char *host_id = NULL;
1860 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1862 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1863 static unsigned int surfxml_buffer_stack_stack[1024];
1865 surfxml_buffer_stack_stack[0] = 0;
1867 surfxml_bufferstack_push(1);
1869 SURFXML_BUFFER_SET(AS_id, struct_peer->V_peer_id);
1871 SURFXML_BUFFER_SET(AS_routing, "Full");
1872 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->V_peer_id);
1874 SURFXML_START_TAG(AS);
1877 host_id = bprintf("peer_%s", struct_peer->V_peer_id);
1878 router_id = bprintf("router_%s", struct_peer->V_peer_id);
1879 link_id_up = bprintf("link_%s_up", struct_peer->V_peer_id);
1880 link_id_down = bprintf("link_%s_down", struct_peer->V_peer_id);
1882 link_router = bprintf("%s_link_router", struct_peer->V_peer_id);
1883 link_backbone = bprintf("%s_backbone", struct_peer->V_peer_id);
1885 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, struct_peer->V_peer_power);
1886 A_surfxml_host_state = A_surfxml_host_state_ON;
1887 SURFXML_BUFFER_SET(host_id, host_id);
1888 SURFXML_BUFFER_SET(host_power, struct_peer->V_peer_power);
1889 SURFXML_BUFFER_SET(host_availability, "1.0");
1890 SURFXML_BUFFER_SET(host_availability_file, struct_peer->V_peer_availability_trace);
1891 SURFXML_BUFFER_SET(host_state_file, struct_peer->V_peer_state_trace);
1892 SURFXML_BUFFER_SET(host_coordinates, "");
1893 SURFXML_BUFFER_SET(host_core, "1.0");
1894 SURFXML_START_TAG(host);
1895 SURFXML_END_TAG(host);
1897 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->V_peer_coord);
1898 SURFXML_BUFFER_SET(router_id, router_id);
1899 SURFXML_BUFFER_SET(router_coordinates, struct_peer->V_peer_coord);
1900 SURFXML_START_TAG(router);
1901 SURFXML_END_TAG(router);
1903 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, struct_peer->V_peer_bw_in, struct_peer->V_peer_lat);
1904 A_surfxml_link_state = A_surfxml_link_state_ON;
1905 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1906 SURFXML_BUFFER_SET(link_id, link_id_up);
1907 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_in);
1908 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1909 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1910 SURFXML_BUFFER_SET(link_latency_file, "");
1911 SURFXML_BUFFER_SET(link_state_file, "");
1912 SURFXML_START_TAG(link);
1913 SURFXML_END_TAG(link);
1915 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, struct_peer->V_peer_bw_out, struct_peer->V_peer_lat);
1916 A_surfxml_link_state = A_surfxml_link_state_ON;
1917 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1918 SURFXML_BUFFER_SET(link_id, link_id_down);
1919 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_out);
1920 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1921 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1922 SURFXML_BUFFER_SET(link_latency_file, "");
1923 SURFXML_BUFFER_SET(link_state_file, "");
1924 SURFXML_START_TAG(link);
1925 SURFXML_END_TAG(link);
1930 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1931 XBT_DEBUG("symmetrical=\"NO\">");
1932 SURFXML_BUFFER_SET(route_src, host_id);
1933 SURFXML_BUFFER_SET(route_dst, router_id);
1934 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1935 SURFXML_START_TAG(route);
1937 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1938 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1939 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1940 SURFXML_START_TAG(link_ctn);
1941 SURFXML_END_TAG(link_ctn);
1943 XBT_DEBUG("</route>");
1944 SURFXML_END_TAG(route);
1947 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1948 XBT_DEBUG("symmetrical=\"NO\">");
1949 SURFXML_BUFFER_SET(route_src, router_id);
1950 SURFXML_BUFFER_SET(route_dst, host_id);
1951 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1952 SURFXML_START_TAG(route);
1954 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
1955 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
1956 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1957 SURFXML_START_TAG(link_ctn);
1958 SURFXML_END_TAG(link_ctn);
1960 XBT_DEBUG("</route>");
1961 SURFXML_END_TAG(route);
1964 SURFXML_END_TAG(AS);
1967 //xbt_dynar_free(&tab_elements_num);
1971 free(link_backbone);
1974 surfxml_bufferstack_pop(1);
1977 static void routing_parse_Srandom(void)
1979 double mean, std, min, max, seed;
1980 char *random_id = A_surfxml_random_id;
1981 char *random_radical = A_surfxml_random_radical;
1982 char *rd_name = NULL;
1984 surf_parse_get_double(&mean,A_surfxml_random_mean);
1985 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
1986 surf_parse_get_double(&min,A_surfxml_random_min);
1987 surf_parse_get_double(&max,A_surfxml_random_max);
1988 surf_parse_get_double(&seed,A_surfxml_random_seed);
1992 random_data_t random = xbt_new0(s_random_data_t, 1);
1995 xbt_dynar_t radical_elements;
1999 xbt_dynar_t radical_ends;
2001 random->generator = A_surfxml_random_generator;
2002 random->seed = seed;
2006 /* Check user stupidities */
2008 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2010 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2013 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2016 /* normalize the mean and standard deviation before storing */
2017 random->mean = (mean - min) / (max - min);
2018 random->std = std / (max - min);
2020 if (random->mean * (1 - random->mean) < random->std * random->std)
2021 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2022 random->mean, random->std);
2024 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2034 if(xbt_dict_size(random_value)==0)
2035 random_value = xbt_dict_new();
2037 if(!strcmp(random_radical,""))
2039 res = random_generate(random);
2040 rd_value = bprintf("%f",res);
2041 xbt_dict_set(random_value, random_id, rd_value, free);
2045 radical_elements = xbt_str_split(random_radical, ",");
2046 xbt_dynar_foreach(radical_elements, iter, groups) {
2047 radical_ends = xbt_str_split(groups, "-");
2048 switch (xbt_dynar_length(radical_ends)) {
2050 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2051 res = random_generate(random);
2052 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2053 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2057 case 2: surf_parse_get_int(&start,
2058 xbt_dynar_get_as(radical_ends, 0, char *));
2059 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2060 for (i = start; i <= end; i++) {
2061 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2062 res = random_generate(random);
2063 tmpbuf = bprintf("%s%d",random_id,i);
2064 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2069 XBT_INFO("Malformed radical");
2072 res = random_generate(random);
2073 rd_name = bprintf("%s_router",random_id);
2074 rd_value = bprintf("%f",res);
2075 xbt_dict_set(random_value, rd_name, rd_value, free);
2077 xbt_dynar_free(&radical_ends);
2080 xbt_dynar_free(&radical_elements);
2084 static void routing_parse_Erandom(void)
2086 /*xbt_dict_cursor_t cursor = NULL;
2090 xbt_dict_foreach(random_value, cursor, key, elem) {
2091 XBT_DEBUG("%s = %s",key,elem);
2097 * New methods to init the routing model component from the lua script
2102 * add a host to the network element list
2105 void routing_add_host(const char *host_id)
2107 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2111 * Set a new link on the actual list of link for a route or ASroute
2113 void routing_add_link(const char *link_id)
2115 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2119 *Set the endpoints for a route
2121 void routing_set_route(const char *src_id, const char *dst_id)
2123 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2127 * Store the route by calling parse_E_route_store_route
2129 void routing_store_route(void)
2131 parse_E_route_store_route();