1 /* Copyright (c) 2009, 2010, 2011. 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 */
9 #include "simgrid/platf.h" // platform creation API
11 #include "surf_routing_private.h"
12 #include "surf/surf_routing.h"
13 #include "surf/surfxml_parse_values.h"
16 int ROUTING_HOST_LEVEL; //Routing level
17 int SURF_CPU_LEVEL; //Surf cpu level
18 int SURF_WKS_LEVEL; //Surf workstation level
19 int SIMIX_HOST_LEVEL; //Simix level
20 int MSG_HOST_LEVEL; //Msg level
21 int SD_HOST_LEVEL; //Simdag level
22 int COORD_HOST_LEVEL; //Coordinates level
23 int NS3_HOST_LEVEL; //host node for ns3
26 int SD_LINK_LEVEL; //Simdag level
27 int SURF_LINK_LEVEL; //Surf level
28 int NS3_LINK_LEVEL; //link for ns3
30 xbt_lib_t as_router_lib;
31 int ROUTING_ASR_LEVEL; //Routing level
32 int COORD_ASR_LEVEL; //Coordinates level
33 int NS3_ASR_LEVEL; //host node for ns3
35 static xbt_dict_t patterns = NULL;
36 static xbt_dict_t random_value = NULL;
39 routing_global_t global_routing = NULL;
40 routing_component_t current_routing = NULL;
41 model_type_t current_routing_model = NULL;
43 /* global parse functions */
44 xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
45 static const char *src = NULL; /* temporary store the source name of a route */
46 static const char *dst = NULL; /* temporary store the destination name of a route */
47 static char *gw_src = NULL; /* temporary store the gateway source name of a route */
48 static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */
49 static double_f_cpvoid_t get_link_latency = NULL;
50 xbt_dict_t cluster_host_link = NULL; /* for tag cluster */
52 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
54 static void routing_parse_Speer(void); /* peer bypass */
55 static void routing_parse_Srandom(void); /* random bypass */
56 static void routing_parse_Erandom(void); /* random bypass */
58 static void routing_parse_Sconfig(void); /* config Tag */
59 static void routing_parse_Econfig(void); /* config Tag */
61 static char* replace_random_parameter(char * chaine);
62 static void clean_routing_after_parse(void);
64 /* this lines are only for replace use like index in the model table */
69 SURF_MODEL_DIJKSTRACACHE,
76 struct s_model_type routing_models[] = { {"Full",
77 "Full routing data (fast, large memory requirements, fully expressive)",
83 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
84 model_floyd_create, model_floyd_load, model_floyd_unload,
87 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
88 model_dijkstra_create, model_dijkstra_both_load,
89 model_dijkstra_both_unload, model_dijkstra_both_end},
91 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
92 model_dijkstracache_create, model_dijkstra_both_load,
93 model_dijkstra_both_unload, model_dijkstra_both_end},
94 {"none", "No routing (usable with Constant network only)",
95 model_none_create, model_none_load, model_none_unload, model_none_end},
96 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
97 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
98 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
99 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
100 {"Cluster", "Cluster routing", model_cluster_create,
101 model_rulebased_load, model_rulebased_unload, model_rulebased_end},
102 {NULL, NULL, NULL, NULL, NULL, NULL}
105 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
107 double src_coord, dst_coord;
109 src_coord = atof(xbt_dynar_get_as(src, index, char *));
110 dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
112 return (src_coord-dst_coord)*(src_coord-dst_coord);
116 static double base_vivaldi_get_latency (const char *src, const char *dst)
118 double euclidean_dist;
119 xbt_dynar_t src_ctn, dst_ctn;
120 src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
121 if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
122 dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
123 if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
125 if(dst_ctn == NULL || src_ctn == NULL)
126 xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn);
128 euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
129 + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
131 xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
134 return euclidean_dist / 1000;
137 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
139 if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
140 int need_to_clean = e_route?0:1;
142 e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
143 latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
144 if(need_to_clean) generic_free_extended_route(e_route);
147 return base_vivaldi_get_latency(src,dst);
152 * \brief Add a "host" to the network element list
154 static void parse_S_host(const char *host_id, const char* coord)
156 network_element_info_t info = NULL;
157 if (current_routing->hierarchy == SURF_ROUTING_NULL)
158 current_routing->hierarchy = SURF_ROUTING_BASE;
159 xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
160 "Reading a host, processing unit \"%s\" already exists",
162 xbt_assert(current_routing->set_processing_unit,
163 "no defined method \"set_processing_unit\" in \"%s\"",
164 current_routing->name);
165 (*(current_routing->set_processing_unit)) (current_routing, host_id);
166 info = xbt_new0(s_network_element_info_t, 1);
167 info->rc_component = current_routing;
168 info->rc_type = SURF_NETWORK_ELEMENT_HOST;
169 xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
170 if (strcmp(coord,"")) {
171 if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
172 xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
173 xbt_dynar_shrink(ctn, 0);
174 xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
178 static void parse_E_host(void)
180 xbt_dict_cursor_t cursor = NULL;
184 xbt_dict_foreach(current_property_set, cursor, key, elem) {
185 XBT_DEBUG("property : %s = %s",key,elem);
190 * \brief Add a host to the network element list from XML
192 static void parse_S_host_XML(surf_parsing_host_arg_t h)
194 parse_S_host(h->V_host_id, h->V_host_coord);
196 static void parse_E_host_XML(void)
202 * \brief Add a host to the network element list from lua script
204 static void parse_S_host_lua(const char *host_id, const char *coord)
206 parse_S_host(host_id, coord);
211 * \brief Add a "router" to the network element list
213 static void parse_S_router(void)
215 network_element_info_t info = NULL;
216 if (current_routing->hierarchy == SURF_ROUTING_NULL)
217 current_routing->hierarchy = SURF_ROUTING_BASE;
218 xbt_assert(!xbt_lib_get_or_null(as_router_lib,struct_router->V_router_id, ROUTING_ASR_LEVEL),
219 "Reading a router, processing unit \"%s\" already exists",
220 struct_router->V_router_id);
221 xbt_assert(current_routing->set_processing_unit,
222 "no defined method \"set_processing_unit\" in \"%s\"",
223 current_routing->name);
224 (*(current_routing->set_processing_unit)) (current_routing,
225 struct_router->V_router_id);
226 info = xbt_new0(s_network_element_info_t, 1);
227 info->rc_component = current_routing;
228 info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
230 xbt_lib_set(as_router_lib,struct_router->V_router_id,ROUTING_ASR_LEVEL,(void *) info);
231 if (strcmp(A_surfxml_router_coordinates,"")) {
232 if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
233 xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
234 xbt_dynar_shrink(ctn, 0);
235 xbt_lib_set(as_router_lib,struct_router->V_router_id,COORD_ASR_LEVEL,(void *) ctn);
240 * brief Add a "router" to the network element list from XML description
242 static void parse_S_router_XML(void)
244 return parse_S_router();
248 * brief Add a "router" to the network element list from XML description
250 static void parse_S_router_lua(const char* router_id)
252 struct_router->V_router_id = xbt_strdup(router_id);
253 struct_router->V_router_coord = xbt_strdup("");
254 return parse_S_router();
258 * \brief Set the endponints for a route
260 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
262 if (src != NULL && dst != NULL && link_list != NULL)
263 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
267 xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
268 "Some limits are null in the route between \"%s\" and \"%s\"",
270 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
274 * \brief Set the endpoints for a route from XML
276 static void parse_S_route_new_and_endpoints_XML(void)
278 parse_S_route_new_and_endpoints(A_surfxml_route_src,
279 A_surfxml_route_dst);
283 * \brief Set the endpoints for a route from lua
285 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
287 parse_S_route_new_and_endpoints(id_src, id_dst);
291 * \brief Set the endponints and gateways for a ASroute
293 static void parse_S_ASroute_new_and_endpoints(void)
295 if (src != NULL && dst != NULL && link_list != NULL)
296 THROWF(arg_error, 0, "Route between %s to %s can not be defined",
297 A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
298 src = A_surfxml_ASroute_src;
299 dst = A_surfxml_ASroute_dst;
300 gw_src = A_surfxml_ASroute_gw_src;
301 gw_dst = A_surfxml_ASroute_gw_dst;
302 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
303 || strlen(gw_dst) > 0,
304 "Some limits are null in the route between \"%s\" and \"%s\"",
306 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
310 * \brief Set the endponints for a bypassRoute
312 static void parse_S_bypassRoute_new_and_endpoints(void)
314 if (src != NULL && dst != NULL && link_list != NULL)
316 "Bypass Route between %s to %s can not be defined",
317 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
318 src = A_surfxml_bypassRoute_src;
319 dst = A_surfxml_bypassRoute_dst;
320 gw_src = A_surfxml_bypassRoute_gw_src;
321 gw_dst = A_surfxml_bypassRoute_gw_dst;
322 xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
323 || strlen(gw_dst) > 0,
324 "Some limits are null in the route between \"%s\" and \"%s\"",
326 link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
330 * \brief Set a new link on the actual list of link for a route or ASroute
332 static void parse_E_link_ctn_new_elem(const char *link_id)
335 val = xbt_strdup(link_id);
336 xbt_dynar_push(link_list, &val);
340 * \brief Set a new link on the actual list of link for a route or ASroute from XML
343 static void parse_E_link_ctn_new_elem_XML(void)
345 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
346 parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
347 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
348 char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
349 parse_E_link_ctn_new_elem(link_id);
352 if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
353 char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
354 parse_E_link_ctn_new_elem(link_id);
360 * \brief Set a new link on the actual list of link for a route or ASroute from lua
362 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
364 parse_E_link_ctn_new_elem(link_id);
368 * \brief Store the route by calling the set_route function of the current routing component
370 static void parse_E_route_store_route(void)
372 name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
373 route->generic_route.link_list = link_list;
374 xbt_assert(current_routing->set_route,
375 "no defined method \"set_route\" in \"%s\"",
376 current_routing->name);
377 (*(current_routing->set_route)) (current_routing, src, dst, route);
384 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
386 static void parse_E_ASroute_store_route(void)
388 name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
389 e_route->generic_route.link_list = link_list;
390 e_route->src_gateway = xbt_strdup(gw_src);
391 e_route->dst_gateway = xbt_strdup(gw_dst);
392 xbt_assert(current_routing->set_ASroute,
393 "no defined method \"set_ASroute\" in \"%s\"",
394 current_routing->name);
395 (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
404 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
406 static void parse_E_bypassRoute_store_route(void)
408 route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
409 e_route->generic_route.link_list = link_list;
410 e_route->src_gateway = xbt_strdup(gw_src);
411 e_route->dst_gateway = xbt_strdup(gw_dst);
412 xbt_assert(current_routing->set_bypassroute,
413 "no defined method \"set_bypassroute\" in \"%s\"",
414 current_routing->name);
415 (*(current_routing->set_bypassroute)) (current_routing, src, dst,
425 * \brief Make a new routing component to the platform
427 * Add a new autonomous system to the platform. Any elements (such as host,
428 * router or sub-AS) added after this call and before the corresponding call
429 * to sg_platf_new_AS_close() will be added to this AS.
431 * Once this function was called, the configuration concerning the used
432 * models cannot be changed anymore.
434 * @param AS_id name of this autonomous system. Must be uniq in the platform
435 * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
437 void sg_platf_new_AS_open(const char *AS_id, const char *wanted_routing_type)
439 routing_component_t new_routing;
440 model_type_t model = NULL;
443 surf_parse_models_setup(); /* ensure that the models are created after the last <config> tag and before the first <AS>-like */
445 /* search the routing model */
446 for (cpt = 0; routing_models[cpt].name; cpt++)
447 if (!strcmp(wanted_routing_type, routing_models[cpt].name))
448 model = &routing_models[cpt];
449 /* if its not exist, error */
451 fprintf(stderr, "Routing model %s not found. Existing models:\n",
452 wanted_routing_type);
453 for (cpt = 0; routing_models[cpt].name; cpt++)
454 fprintf(stderr, " %s: %s\n", routing_models[cpt].name,
455 routing_models[cpt].desc);
459 /* make a new routing component */
460 new_routing = (routing_component_t) (*(model->create)) ();
461 new_routing->routing = model;
462 new_routing->hierarchy = SURF_ROUTING_NULL;
463 new_routing->name = xbt_strdup(AS_id);
464 new_routing->routing_sons = xbt_dict_new();
466 /* Hack for Vivaldi */
467 if(!strcmp(model->name,"Vivaldi"))
468 new_routing->get_latency = vivaldi_get_link_latency;
470 if (current_routing == NULL && global_routing->root == NULL) {
472 /* it is the first one */
473 new_routing->routing_father = NULL;
474 global_routing->root = new_routing;
476 } else if (current_routing != NULL && global_routing->root != NULL) {
478 xbt_assert(!xbt_dict_get_or_null
479 (current_routing->routing_sons, AS_id),
480 "The AS \"%s\" already exists", AS_id);
481 /* it is a part of the tree */
482 new_routing->routing_father = current_routing;
483 /* set the father behavior */
484 if (current_routing->hierarchy == SURF_ROUTING_NULL)
485 current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
486 /* add to the sons dictionary */
487 xbt_dict_set(current_routing->routing_sons, AS_id,
488 (void *) new_routing, NULL);
489 /* add to the father element list */
490 (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
491 /* unload the prev parse rules */
492 (*(current_routing->routing->unload)) ();
495 THROWF(arg_error, 0, "All defined components must be belong to a AS");
497 /* set the new parse rules */
498 (*(new_routing->routing->load)) ();
499 /* set the new current component of the tree */
500 current_routing = new_routing;
504 * \brief Specify that the current description of AS is finished
506 * Once you've declared all the content of your AS, you have to close
507 * it with this call. Your AS is not usable until you call this function.
509 * @fixme: this call is not as robust as wanted: bad things WILL happen
510 * if you call it twice for the same AS, or if you forget calling it, or
511 * even if you add stuff to a closed AS
514 void sg_platf_new_AS_close() {
516 if (current_routing == NULL) {
517 THROWF(arg_error, 0, "Close an AS, but none was under construction");
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)) ();
535 /* Aux Business methods */
538 * \brief Get the AS name of the element
540 * \param name the host name
543 static char* elements_As_name(const char *name)
545 routing_component_t as_comp;
547 /* (1) find the as where the host is located */
548 as_comp = ((network_element_info_t)
549 xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
550 return as_comp->name;
555 * \brief Get the AS father and the first elements of the chain
557 * \param src the source host name
558 * \param dst the destination host name
560 * Get the common father of the to processing units, and the first different
561 * father in the chain
563 static void elements_father(const char *src, const char *dst,
564 routing_component_t *res_father,
565 routing_component_t *res_src,
566 routing_component_t *res_dst)
568 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
569 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
570 routing_component_t src_as, dst_as;
571 routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
572 routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
575 routing_component_t current;
576 routing_component_t current_src;
577 routing_component_t current_dst;
578 routing_component_t father;
580 /* (1) find the as where the src and dst are located */
581 network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
583 network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
586 src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
588 dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
589 src_as = src_data->rc_component;
590 dst_as = dst_data->rc_component;
592 xbt_assert(src_as && dst_as,
593 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
595 /* (2) find the path to the root routing component */
596 for (current = src_as ; current != NULL ; current = current->routing_father) {
597 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
598 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
599 path_src[index_src++] = current;
601 for (current = dst_as ; current != NULL ; current = current->routing_father) {
602 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
603 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
604 path_dst[index_dst++] = current;
607 /* (3) find the common father */
609 current_src = path_src[--index_src];
610 current_dst = path_dst[--index_dst];
611 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
613 /* (4) they are not in the same routing component, make the path */
614 if (current_src == current_dst)
615 father = current_src;
617 father = path_src[index_src + 1];
619 /* (5) result generation */
620 *res_father = father; /* first the common father of src and dst */
621 *res_src = current_src; /* second the first different father of src */
622 *res_dst = current_dst; /* three the first different father of dst */
624 #undef ELEMENTS_FATHER_MAXDEPTH
627 /* Global Business methods */
630 * \brief Recursive function for get_route_latency
632 * \param src the source host name
633 * \param dst the destination host name
634 * \param *e_route the route where the links are stored
635 * \param *latency the latency, if needed
637 * This function is called by "get_route" and "get_latency". It allows to walk
638 * recursively through the routing components tree.
640 static void _get_route_latency(const char *src, const char *dst,
641 xbt_dynar_t *route, double *latency)
643 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src, dst);
644 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
646 routing_component_t common_father;
647 routing_component_t src_father;
648 routing_component_t dst_father;
649 elements_father(src, dst, &common_father, &src_father, &dst_father);
651 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
653 route_extended_t e_route = NULL;
655 e_route = common_father->get_route(common_father, src, dst);
656 xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
657 *route = e_route->generic_route.link_list;
660 *latency = common_father->get_latency(common_father, src, dst, e_route);
661 xbt_assert(*latency >= 0.0,
662 "latency error on route between \"%s\" and \"%s\"", src, dst);
665 xbt_free(e_route->src_gateway);
666 xbt_free(e_route->dst_gateway);
670 } else { /* SURF_ROUTING_RECURSIVE */
672 route_extended_t e_route_bypass = NULL;
673 if (common_father->get_bypass_route)
674 e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
676 xbt_assert(!latency || !e_route_bypass,
677 "Bypass cannot work yet with get_latency");
679 route_extended_t e_route_cnt = e_route_bypass
681 : common_father->get_route(common_father,
682 src_father->name, dst_father->name);
684 xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
685 src_father->name, dst_father->name);
687 xbt_assert((e_route_cnt->src_gateway == NULL) ==
688 (e_route_cnt->dst_gateway == NULL),
689 "bad gateway for route between \"%s\" and \"%s\"", src, dst);
692 *route = xbt_dynar_new(global_routing->size_of_link, NULL);
695 *latency = common_father->get_latency(common_father,
696 src_father->name, dst_father->name,
698 xbt_assert(*latency >= 0.0,
699 "latency error on route between \"%s\" and \"%s\"",
700 src_father->name, dst_father->name);
706 if (strcmp(src, e_route_cnt->src_gateway)) {
708 xbt_dynar_t route_src;
710 _get_route_latency(src, e_route_cnt->src_gateway,
711 (route ? &route_src : NULL),
712 (latency ? &latency_src : NULL));
714 xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
715 src, e_route_cnt->src_gateway);
716 xbt_dynar_foreach(route_src, cpt, link) {
717 xbt_dynar_push(*route, &link);
719 xbt_dynar_free(&route_src);
722 xbt_assert(latency_src >= 0.0,
723 "latency error on route between \"%s\" and \"%s\"",
724 src, e_route_cnt->src_gateway);
725 *latency += latency_src;
730 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
731 xbt_dynar_push(*route, &link);
735 if (strcmp(e_route_cnt->dst_gateway, dst)) {
737 xbt_dynar_t route_dst;
739 _get_route_latency(e_route_cnt->dst_gateway, dst,
740 (route ? &route_dst : NULL),
741 (latency ? &latency_dst : NULL));
743 xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
744 e_route_cnt->dst_gateway, dst);
745 xbt_dynar_foreach(route_dst, cpt, link) {
746 xbt_dynar_push(*route, &link);
748 xbt_dynar_free(&route_dst);
751 xbt_assert(latency_dst >= 0.0,
752 "latency error on route between \"%s\" and \"%s\"",
753 e_route_cnt->dst_gateway, dst);
754 *latency += latency_dst;
758 generic_free_extended_route(e_route_cnt);
763 * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
765 static void get_route_latency(const char *src, const char *dst,
766 xbt_dynar_t *route, double *latency, int cleanup)
768 _get_route_latency(src, dst, route, latency);
769 xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
770 xbt_assert(!latency || *latency >= 0.0,
771 "latency error on route between \"%s\" and \"%s\"", src, dst);
773 xbt_dynar_free(&global_routing->last_route);
774 global_routing->last_route = cleanup ? *route : NULL;
779 * \brief Generic method: find a route between hosts
781 * \param src the source host name
782 * \param dst the destination host name
784 * walk through the routing components tree and find a route between hosts
785 * by calling the differents "get_route" functions in each routing component.
786 * No need to free the returned dynar. It will be freed at the next call.
788 static xbt_dynar_t get_route(const char *src, const char *dst)
790 xbt_dynar_t route = NULL;
791 get_route_latency(src, dst, &route, NULL, 1);
796 * \brief Generic method: find a route between hosts
798 * \param src the source host name
799 * \param dst the destination host name
801 * same as get_route, but return NULL if any exception is raised.
803 static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
805 xbt_dynar_t route = NULL;
808 get_route_latency(src, dst, &route, NULL, 1);
810 xbt_ex_free(exception);
817 * \brief Generic method: find a route between hosts
819 * \param src the source host name
820 * \param dst the destination host name
822 * walk through the routing components tree and find a route between hosts
823 * by calling the differents "get_route" functions in each routing component.
824 * Leaves the caller the responsability to clean the returned dynar.
826 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
828 xbt_dynar_t route = NULL;
829 get_route_latency(src, dst, &route, NULL, 0);
834 static double get_latency(const char *src, const char *dst)
836 double latency = -1.0;
837 get_route_latency(src, dst, NULL, &latency, 0);
841 static int surf_parse_models_setup_already_called=0;
842 /* Call the last initialization functions, that must be called after the
843 * <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
845 void surf_parse_models_setup()
847 if (surf_parse_models_setup_already_called)
849 surf_parse_models_setup_already_called=1;
850 routing_parse_Erandom();
851 surf_config_models_setup();
856 * \brief Recursive function for finalize
858 * \param rc the source host name
860 * This fuction is call by "finalize". It allow to finalize the
861 * AS or routing components. It delete all the structures.
863 static void _finalize(routing_component_t rc)
866 xbt_dict_cursor_t cursor = NULL;
868 routing_component_t elem;
869 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
872 xbt_dict_t tmp_sons = rc->routing_sons;
873 char *tmp_name = rc->name;
874 xbt_dict_free(&tmp_sons);
876 xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
877 current_routing->name);
878 (*(rc->finalize)) (rc);
883 * \brief Generic method: delete all the routing structures
885 * walk through the routing components tree and delete the structures
886 * by calling the differents "finalize" functions in each routing component
888 static void finalize(void)
890 /* delete recursibly all the tree */
891 _finalize(global_routing->root);
892 /* delete last_route */
893 xbt_dynar_free(&(global_routing->last_route));
894 /* delete global routing structure */
895 xbt_free(global_routing);
896 /* make sure that we will reinit the models while loading the platf once reinited -- HACK but there is no proper surf_routing_init() */
897 surf_parse_models_setup_already_called = 0;
900 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
902 xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
904 //adding my one link routes
907 xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
909 xbt_dynar_foreach(onelink_mine, cpt, link) {
910 xbt_dynar_push(ret, &link);
915 xbt_dict_cursor_t cursor = NULL;
916 routing_component_t rc_child;
917 xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
918 xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
920 xbt_dynar_foreach(onelink_child, cpt, link) {
921 xbt_dynar_push(ret, &link);
928 static xbt_dynar_t get_onelink_routes(void)
930 return recursive_get_onelink_routes(global_routing->root);
933 e_surf_network_element_type_t get_network_element_type(const char
936 network_element_info_t rc = NULL;
938 rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
939 if(rc) return rc->rc_type;
941 rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
942 if(rc) return rc->rc_type;
944 return SURF_NETWORK_ELEMENT_NULL;
948 * \brief Generic method: create the global routing schema
950 * Make a global routing structure and set all the parsing functions.
952 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
954 /* config the uniq global routing */
955 global_routing = xbt_new0(s_routing_global_t, 1);
956 global_routing->root = NULL;
957 global_routing->get_route = get_route;
958 global_routing->get_route_or_null = get_route_or_null;
959 global_routing->get_latency = get_latency;
960 global_routing->get_route_no_cleanup = get_route_no_cleanup;
961 global_routing->get_onelink_routes = get_onelink_routes;
962 global_routing->get_route_latency = get_route_latency;
963 global_routing->get_network_element_type = get_network_element_type;
964 global_routing->finalize = finalize;
965 global_routing->loopback = loopback;
966 global_routing->size_of_link = size_of_links;
967 global_routing->last_route = NULL;
968 get_link_latency = get_link_latency_fun;
969 /* no current routing at moment */
970 current_routing = NULL;
972 /* parse generic elements */
973 surf_parse_host_add_cb(parse_S_host_XML);
974 surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
975 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
977 surfxml_add_callback(STag_surfxml_route_cb_list,
978 &parse_S_route_new_and_endpoints_XML);
979 surfxml_add_callback(STag_surfxml_ASroute_cb_list,
980 &parse_S_ASroute_new_and_endpoints);
981 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
982 &parse_S_bypassRoute_new_and_endpoints);
984 surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
985 &parse_E_link_ctn_new_elem_XML);
987 surfxml_add_callback(ETag_surfxml_route_cb_list,
988 &parse_E_route_store_route);
989 surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
990 &parse_E_ASroute_store_route);
991 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
992 &parse_E_bypassRoute_store_route);
994 surfxml_add_callback(STag_surfxml_cluster_cb_list,
995 &routing_parse_Scluster);
997 surfxml_add_callback(STag_surfxml_peer_cb_list,
998 &routing_parse_Speer);
1000 surfxml_add_callback(ETag_surfxml_platform_cb_list,
1001 &clean_routing_after_parse);
1004 instr_routing_define_callbacks();
1008 void surf_parse_add_callback_config(void)
1010 surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
1011 surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
1012 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
1013 surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1016 /* ************************************************** */
1017 /* ********** PATERN FOR NEW ROUTING **************** */
1019 /* The minimal configuration of a new routing model need the next functions,
1020 * also you need to set at the start of the file, the new model in the model
1021 * list. Remember keep the null ending of the list.
1023 /*** Routing model structure ***/
1025 // s_routing_component_t generic_routing;
1026 // /* things that your routing model need */
1027 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1029 /*** Parse routing model functions ***/
1030 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1031 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1032 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1033 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1034 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1036 /*** Business methods ***/
1037 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1038 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1039 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1041 /*** Creation routing model functions ***/
1042 // static void* model_NEW_create(void) {
1043 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1044 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1045 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1046 // new_component->generic_routing.set_route = model_NEW_set_route;
1047 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1048 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1049 // new_component->generic_routing.get_route = NEW_get_route;
1050 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1051 // new_component->generic_routing.finalize = NEW_finalize;
1052 // /* initialization of internal structures */
1053 // return new_component;
1054 // } /* mandatory */
1055 // static void model_NEW_load(void) {} /* mandatory */
1056 // static void model_NEW_unload(void) {} /* mandatory */
1057 // static void model_NEW_end(void) {} /* mandatory */
1059 /* ************************************************************************** */
1060 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1062 void generic_set_processing_unit(routing_component_t rc,
1065 XBT_DEBUG("Load process unit \"%s\"", name);
1066 int *id = xbt_new0(int, 1);
1067 xbt_dict_t _to_index;
1068 _to_index = current_routing->to_index;
1069 *id = xbt_dict_length(_to_index);
1070 xbt_dict_set(_to_index, name, id, xbt_free);
1073 void generic_set_autonomous_system(routing_component_t rc,
1076 XBT_DEBUG("Load Autonomous system \"%s\"", name);
1077 int *id = xbt_new0(int, 1);
1078 xbt_dict_t _to_index;
1079 _to_index = current_routing->to_index;
1080 *id = xbt_dict_length(_to_index);
1081 xbt_dict_set(_to_index, name, id, xbt_free);
1084 int surf_pointer_resource_cmp(const void *a, const void *b)
1089 int surf_link_resource_cmp(const void *a, const void *b)
1091 return !!memcmp(a,b,global_routing->size_of_link);
1094 void generic_set_bypassroute(routing_component_t rc,
1095 const char *src, const char *dst,
1096 route_extended_t e_route)
1098 XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1099 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1102 route_name = bprintf("%s#%s", src, dst);
1103 xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1104 "Invalid count of links, must be greater than zero (%s,%s)",
1106 xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1107 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1108 src, e_route->src_gateway, dst, e_route->dst_gateway);
1110 route_extended_t new_e_route =
1111 generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1112 xbt_dynar_free(&(e_route->generic_route.link_list));
1115 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1116 (void (*)(void *)) generic_free_extended_route);
1117 xbt_free(route_name);
1120 /* ************************************************************************** */
1121 /* *********************** GENERIC BUSINESS METHODS ************************* */
1123 double generic_get_link_latency(routing_component_t rc,
1124 const char *src, const char *dst,
1125 route_extended_t route)
1127 int need_to_clean = route?0:1;
1130 double latency = 0.0;
1132 route = route?route:rc->get_route(rc,src,dst);
1134 xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1135 latency += get_link_latency(link);
1137 if(need_to_clean) generic_free_extended_route(route);
1141 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1143 xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1146 route_extended_t generic_get_bypassroute(routing_component_t rc,
1150 xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1151 routing_component_t src_as, dst_as;
1152 int index_src, index_dst;
1153 xbt_dynar_t path_src = NULL;
1154 xbt_dynar_t path_dst = NULL;
1155 routing_component_t current = NULL;
1156 routing_component_t *current_src = NULL;
1157 routing_component_t *current_dst = NULL;
1159 /* (1) find the as where the src and dst are located */
1160 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1161 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1162 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1163 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1165 if(src_data == NULL || dst_data == NULL)
1166 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1167 src, dst, rc->name);
1169 src_as = ((network_element_info_t)src_data)->rc_component;
1170 dst_as = ((network_element_info_t)dst_data)->rc_component;
1172 /* (2) find the path to the root routing component */
1173 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1175 while (current != NULL) {
1176 xbt_dynar_push(path_src, ¤t);
1177 current = current->routing_father;
1179 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1181 while (current != NULL) {
1182 xbt_dynar_push(path_dst, ¤t);
1183 current = current->routing_father;
1186 /* (3) find the common father */
1187 index_src = path_src->used - 1;
1188 index_dst = path_dst->used - 1;
1189 current_src = xbt_dynar_get_ptr(path_src, index_src);
1190 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1191 while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1192 xbt_dynar_pop_ptr(path_src);
1193 xbt_dynar_pop_ptr(path_dst);
1196 current_src = xbt_dynar_get_ptr(path_src, index_src);
1197 current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1200 int max_index_src = path_src->used - 1;
1201 int max_index_dst = path_dst->used - 1;
1203 int max_index = max(max_index_src, max_index_dst);
1206 route_extended_t e_route_bypass = NULL;
1208 for (max = 0; max <= max_index; max++) {
1209 for (i = 0; i < max; i++) {
1210 if (i <= max_index_src && max <= max_index_dst) {
1211 char *route_name = bprintf("%s#%s",
1212 (*(routing_component_t *)
1214 (path_src, i)))->name,
1215 (*(routing_component_t *)
1217 (path_dst, max)))->name);
1219 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1220 xbt_free(route_name);
1224 if (max <= max_index_src && i <= max_index_dst) {
1225 char *route_name = bprintf("%s#%s",
1226 (*(routing_component_t *)
1228 (path_src, max)))->name,
1229 (*(routing_component_t *)
1231 (path_dst, i)))->name);
1233 xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1234 xbt_free(route_name);
1243 if (max <= max_index_src && max <= max_index_dst) {
1244 char *route_name = bprintf("%s#%s",
1245 (*(routing_component_t *)
1247 (path_src, max)))->name,
1248 (*(routing_component_t *)
1250 (path_dst, max)))->name);
1251 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1252 xbt_free(route_name);
1258 xbt_dynar_free(&path_src);
1259 xbt_dynar_free(&path_dst);
1261 route_extended_t new_e_route = NULL;
1263 if (e_route_bypass) {
1265 unsigned int cpt = 0;
1266 new_e_route = xbt_new0(s_route_extended_t, 1);
1267 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1268 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1269 new_e_route->generic_route.link_list =
1270 xbt_dynar_new(global_routing->size_of_link, NULL);
1271 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1272 xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1279 /* ************************************************************************** */
1280 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1283 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1284 void *data, int order)
1290 xbt_dynar_t links = NULL, links_id = NULL;
1292 new_route = xbt_new0(s_route_t, 1);
1293 new_route->link_list =
1294 xbt_dynar_new(global_routing->size_of_link, NULL);
1296 xbt_assert(hierarchy == SURF_ROUTING_BASE,
1297 "the hierarchy type is not SURF_ROUTING_BASE");
1299 links = ((route_t) data)->link_list;
1302 links_id = new_route->link_list;
1304 xbt_dynar_foreach(links, cpt, link_name) {
1307 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1310 xbt_dynar_push(links_id, &link);
1312 xbt_dynar_unshift(links_id, &link);
1314 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1321 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1322 void *data, int order)
1326 route_extended_t e_route, new_e_route;
1329 xbt_dynar_t links = NULL, links_id = NULL;
1331 new_e_route = xbt_new0(s_route_extended_t, 1);
1332 new_e_route->generic_route.link_list =
1333 xbt_dynar_new(global_routing->size_of_link, NULL);
1334 new_e_route->src_gateway = NULL;
1335 new_e_route->dst_gateway = NULL;
1337 xbt_assert(hierarchy == SURF_ROUTING_BASE
1338 || hierarchy == SURF_ROUTING_RECURSIVE,
1339 "the hierarchy type is not defined");
1341 if (hierarchy == SURF_ROUTING_BASE) {
1343 route = (route_t) data;
1344 links = route->link_list;
1346 } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1348 e_route = (route_extended_t) data;
1349 xbt_assert(e_route->src_gateway
1350 && e_route->dst_gateway, "bad gateway, is null");
1351 links = e_route->generic_route.link_list;
1353 /* remeber not erase the gateway names */
1354 new_e_route->src_gateway = strdup(e_route->src_gateway);
1355 new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1358 links_id = new_e_route->generic_route.link_list;
1360 xbt_dynar_foreach(links, cpt, link_name) {
1363 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1366 xbt_dynar_push(links_id, &link);
1368 xbt_dynar_unshift(links_id, &link);
1370 THROWF(mismatch_error, 0, "Link %s not found", link_name);
1376 void generic_free_route(route_t route)
1379 xbt_dynar_free(&(route->link_list));
1384 void generic_free_extended_route(route_extended_t e_route)
1387 xbt_dynar_free(&(e_route->generic_route.link_list));
1388 if (e_route->src_gateway)
1389 xbt_free(e_route->src_gateway);
1390 if (e_route->dst_gateway)
1391 xbt_free(e_route->dst_gateway);
1396 static routing_component_t generic_as_exist(routing_component_t find_from,
1397 routing_component_t to_find)
1399 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1400 xbt_dict_cursor_t cursor = NULL;
1403 routing_component_t elem;
1404 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1405 if (to_find == elem || generic_as_exist(elem, to_find)) {
1416 generic_autonomous_system_exist(routing_component_t rc, char *element)
1418 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1419 routing_component_t element_as, result, elem;
1420 xbt_dict_cursor_t cursor = NULL;
1422 element_as = ((network_element_info_t)
1423 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1424 result = ((routing_component_t) - 1);
1425 if (element_as != rc)
1426 result = generic_as_exist(rc, element_as);
1430 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1431 found = !strcmp(elem->name, element);
1442 generic_processing_units_exist(routing_component_t rc, char *element)
1444 routing_component_t element_as;
1445 element_as = ((network_element_info_t)
1446 xbt_lib_get_or_null(host_lib,
1447 element, ROUTING_HOST_LEVEL))->rc_component;
1448 if (element_as == rc)
1450 return generic_as_exist(rc, element_as);
1453 void generic_src_dst_check(routing_component_t rc, const char *src,
1457 void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1458 void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1459 if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1460 if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1462 if(src_data == NULL || dst_data == NULL)
1463 xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1464 src, dst, rc->name);
1466 routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1467 routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1469 if(src_as != dst_as)
1470 xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1471 src, src_as->name, dst, dst_as->name);
1473 xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1474 src,dst,src_as->name, dst_as->name,rc->name);
1477 static void routing_parse_Sconfig(void)
1479 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1482 static void routing_parse_Econfig(void)
1484 xbt_dict_cursor_t cursor = NULL;
1488 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1489 cfg = bprintf("%s:%s",key,elem);
1490 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1491 xbt_cfg_set_parse(_surf_cfg_set, cfg);
1493 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
1496 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1499 static void parse_create_host_link(int i)
1501 char *host_id, *link_id = NULL;
1502 s_surf_parsing_host_arg_t host;
1503 memset(&host,0,sizeof(host));
1505 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1506 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1508 A_surfxml_host_state = A_surfxml_host_state_ON;
1510 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1511 host.V_host_id = xbt_strdup(host_id);
1512 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1513 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1514 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1515 xbt_str_varsubst(tmp_availability_file,patterns);
1516 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1517 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1518 xbt_free(tmp_availability_file);
1522 XBT_DEBUG("\tavailability_file=\"\"");
1524 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1525 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1526 xbt_str_varsubst(tmp_state_file,patterns);
1527 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1528 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1529 xbt_free(tmp_state_file);
1533 XBT_DEBUG("\tstate_file=\"\"");
1536 host.V_host_power_peak = struct_cluster->S_cluster_power;
1537 host.V_host_power_scale = 1.0;
1538 host.V_host_core = struct_cluster->S_cluster_core;
1539 host.V_host_state_initial = SURF_RESOURCE_ON;
1540 host.V_host_coord = "";
1541 surf_parse_host(&host);
1542 XBT_DEBUG("</host>");
1544 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1545 if(AX_surfxml_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1546 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1547 if(AX_surfxml_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1548 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1550 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1552 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1553 struct_lnk->V_link_id = xbt_strdup(link_id);
1554 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1555 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1556 struct_lnk->V_link_bandwidth_file = NULL;
1557 struct_lnk->V_link_latency_file = NULL;
1558 struct_lnk->V_link_state_file = NULL;
1559 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1560 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1562 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1563 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1566 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1567 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1568 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1569 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1573 ETag_surfxml_host();
1574 ETag_surfxml_link();
1576 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1578 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX){
1579 char* tmp_link = bprintf("%s_UP",link_id);
1580 info->link_up = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1582 tmp_link = bprintf("%s_DOWN",link_id);
1583 info->link_down = xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
1587 info->link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
1588 info->link_down = info->link_up;
1590 xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
1595 void routing_parse_Scluster(void)
1597 if(!cluster_host_link)
1598 cluster_host_link = xbt_dict_new();
1600 static int AX_ptr = 0;
1601 char *host_id, *groups, *link_id = NULL;
1603 s_surf_parsing_host_arg_t host;
1605 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1606 || strcmp(struct_cluster->V_cluster_state_file,"") )
1608 if(xbt_dict_size(patterns)==0)
1609 patterns = xbt_dict_new();
1610 xbt_dict_set(patterns,"id",struct_cluster->V_cluster_id,NULL);
1611 xbt_dict_set(patterns,"prefix",struct_cluster->V_cluster_prefix,NULL);
1612 xbt_dict_set(patterns,"suffix",struct_cluster->V_cluster_suffix,NULL);
1617 xbt_dynar_t radical_elements;
1618 xbt_dynar_t radical_ends;
1620 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1621 static unsigned int surfxml_buffer_stack_stack[1024];
1623 surfxml_buffer_stack_stack[0] = 0;
1624 surfxml_bufferstack_push(1);
1626 SURFXML_BUFFER_SET(AS_id, struct_cluster->V_cluster_id);
1627 SURFXML_BUFFER_SET(AS_routing, "Cluster");
1628 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", struct_cluster->V_cluster_id);
1629 SURFXML_START_TAG(AS);
1632 radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ",");
1633 xbt_dynar_foreach(radical_elements, iter, groups) {
1634 memset(&host,0,sizeof(host));
1636 radical_ends = xbt_str_split(groups, "-");
1637 switch (xbt_dynar_length(radical_ends)) {
1639 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
1640 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, start, struct_cluster->V_cluster_suffix);
1641 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start);
1643 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1644 host.V_host_id = host_id;
1645 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1646 xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1647 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1648 xbt_str_varsubst(tmp_availability_file,patterns);
1649 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1650 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1651 xbt_free(tmp_availability_file);
1655 XBT_DEBUG("\tavailability_file=\"\"");
1657 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1658 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1659 xbt_str_varsubst(tmp_state_file,patterns);
1660 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1661 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1662 xbt_free(tmp_state_file);
1666 XBT_DEBUG("\tstate_file=\"\"");
1669 host.V_host_power_peak = struct_cluster->S_cluster_power;
1670 host.V_host_power_scale = 1.0;
1671 host.V_host_core = struct_cluster->S_cluster_core;
1672 host.V_host_state_initial = SURF_RESOURCE_ON;
1673 host.V_host_coord = "";
1674 surf_parse_host(&host);
1675 XBT_DEBUG("</host>");
1677 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1678 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1679 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1680 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1681 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1683 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1685 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1686 struct_lnk->V_link_id = link_id;
1687 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1688 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1689 struct_lnk->V_link_bandwidth_file = NULL;
1690 struct_lnk->V_link_latency_file = NULL;
1691 struct_lnk->V_link_state_file = NULL;
1692 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1693 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1695 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1696 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1699 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1700 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1701 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1702 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1706 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1707 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1708 ETag_surfxml_host();
1709 ETag_surfxml_link();
1715 surf_parse_get_int(&start,
1716 xbt_dynar_get_as(radical_ends, 0, char *));
1717 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1718 for (i = start; i <= end; i++) {
1719 host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix);
1720 link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i);
1722 A_surfxml_host_state = A_surfxml_host_state_ON;
1724 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, struct_cluster->S_cluster_power);
1725 host.V_host_id = host_id;
1726 if(strcmp(struct_cluster->V_cluster_availability_file,"")){
1727 xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1728 char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file);
1729 xbt_str_varsubst(tmp_availability_file,patterns);
1730 XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file);
1731 host.V_host_power_trace = tmgr_trace_new(tmp_availability_file);
1732 xbt_free(tmp_availability_file);
1736 XBT_DEBUG("\tavailability_file=\"\"");
1738 if(strcmp(struct_cluster->V_cluster_state_file,"")){
1739 char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file);
1740 xbt_str_varsubst(tmp_state_file,patterns);
1741 XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file);
1742 host.V_host_state_trace = tmgr_trace_new(tmp_state_file);
1743 xbt_free(tmp_state_file);
1747 XBT_DEBUG("\tstate_file=\"\"");
1750 host.V_host_power_peak = struct_cluster->S_cluster_power;
1751 host.V_host_power_scale = 1.0;
1752 host.V_host_core = struct_cluster->S_cluster_core;
1753 host.V_host_state_initial = SURF_RESOURCE_ON;
1754 host.V_host_coord = "";
1755 surf_parse_host(&host);
1756 XBT_DEBUG("</host>");
1758 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1759 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1760 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FULLDUPLEX;}
1761 if(struct_cluster->V_cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1762 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1764 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,struct_cluster->S_cluster_bw, struct_cluster->S_cluster_lat);
1766 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1767 struct_lnk->V_link_id = link_id;
1768 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bw;
1769 struct_lnk->V_link_latency = struct_cluster->S_cluster_lat;
1770 struct_lnk->V_link_bandwidth_file = NULL;
1771 struct_lnk->V_link_latency_file = NULL;
1772 struct_lnk->V_link_state_file = NULL;
1773 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1774 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1776 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1777 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1780 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
1781 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1782 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
1783 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
1787 xbt_dict_set(cluster_host_link,host_id,strdup(link_id),free);
1788 // XBT_INFO("key '%s' Value '%s'",host_id,link_id);
1790 ETag_surfxml_host();
1791 ETag_surfxml_link();
1797 XBT_DEBUG("Malformed radical");
1801 xbt_dynar_free(&radical_ends);
1803 xbt_dynar_free(&radical_elements);
1807 XBT_DEBUG("<router id=\"%s\"/>", struct_cluster->S_cluster_router_id);
1808 SURFXML_BUFFER_SET(router_id, struct_cluster->S_cluster_router_id);
1809 SURFXML_BUFFER_SET(router_coordinates, "");
1810 SURFXML_START_TAG(router);
1811 SURFXML_END_TAG(router);
1814 if( (struct_cluster->S_cluster_bb_bw!= 0) && (struct_cluster->S_cluster_bb_lat!=0) ){
1815 char *link_backbone = bprintf("%s_backbone", struct_cluster->V_cluster_id);
1816 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,struct_cluster->S_cluster_bb_bw, struct_cluster->S_cluster_bb_lat);
1818 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1819 if(AX_surfxml_cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1820 {A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;}
1822 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
1823 struct_lnk->V_link_id = xbt_strdup(link_backbone);
1824 struct_lnk->V_link_bandwidth = struct_cluster->S_cluster_bb_bw;
1825 struct_lnk->V_link_latency = struct_cluster->S_cluster_bb_lat;
1826 struct_lnk->V_link_bandwidth_file = NULL;
1827 struct_lnk->V_link_latency_file = NULL;
1828 struct_lnk->V_link_state_file = NULL;
1829 struct_lnk->V_link_state = SURF_RESOURCE_ON;
1830 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
1832 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
1833 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
1835 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
1838 ETag_surfxml_link();
1840 surf_parsing_link_up_down_t info = xbt_new0(s_surf_parsing_link_up_down_t, 1);
1841 info->link_up = xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL);
1842 info->link_down = info->link_up;
1843 xbt_dict_set(cluster_host_link,struct_cluster->V_cluster_id,info,xbt_free);
1844 free(link_backbone);
1849 char *new_suffix = xbt_strdup("");
1851 radical_elements = xbt_str_split(struct_cluster->V_cluster_suffix, ".");
1852 xbt_dynar_foreach(radical_elements, iter, groups) {
1853 if (strcmp(groups, "")) {
1854 char *old_suffix = new_suffix;
1855 new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1860 xbt_dynar_free(&radical_elements);
1861 xbt_free(new_suffix);
1863 if( strcmp(struct_cluster->V_cluster_availability_file,"")
1864 || strcmp(struct_cluster->V_cluster_state_file,"") )
1865 xbt_dict_free(&patterns);
1868 SURFXML_END_TAG(AS);
1871 surfxml_bufferstack_pop(1);
1874 * This function take a string and replace parameters from patterns dict.
1875 * It returns the new value.
1877 static char* replace_random_parameter(char * string)
1879 char *test_string = NULL;
1881 if(xbt_dict_size(random_value)==0)
1884 string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1885 test_string = bprintf("${%s}", string);
1886 test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1888 if (strcmp(test_string,"")) { //if not empty, keep this value.
1890 string = test_string;
1891 } //In other case take old value (without ${})
1897 static void clean_routing_after_parse(void)
1899 xbt_dict_free(&random_value);
1900 xbt_dict_free(&patterns);
1903 static void routing_parse_Speer(void)
1905 static int AX_ptr = 0;
1906 char *host_id = NULL;
1907 char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1909 static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1910 static unsigned int surfxml_buffer_stack_stack[1024];
1912 surfxml_buffer_stack_stack[0] = 0;
1914 surfxml_bufferstack_push(1);
1916 SURFXML_BUFFER_SET(AS_id, struct_peer->V_peer_id);
1918 SURFXML_BUFFER_SET(AS_routing, "Full");
1919 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->V_peer_id);
1921 SURFXML_START_TAG(AS);
1924 host_id = bprintf("peer_%s", struct_peer->V_peer_id);
1925 router_id = bprintf("router_%s", struct_peer->V_peer_id);
1926 link_id_up = bprintf("link_%s_up", struct_peer->V_peer_id);
1927 link_id_down = bprintf("link_%s_down", struct_peer->V_peer_id);
1929 link_router = bprintf("%s_link_router", struct_peer->V_peer_id);
1930 link_backbone = bprintf("%s_backbone", struct_peer->V_peer_id);
1932 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, struct_peer->V_peer_power);
1933 A_surfxml_host_state = A_surfxml_host_state_ON;
1934 SURFXML_BUFFER_SET(host_id, host_id);
1935 SURFXML_BUFFER_SET(host_power, struct_peer->V_peer_power);
1936 SURFXML_BUFFER_SET(host_availability, "1.0");
1937 SURFXML_BUFFER_SET(host_availability_file, struct_peer->V_peer_availability_trace);
1938 SURFXML_BUFFER_SET(host_state_file, struct_peer->V_peer_state_trace);
1939 SURFXML_BUFFER_SET(host_coordinates, "");
1940 SURFXML_BUFFER_SET(host_core, "1.0");
1941 SURFXML_START_TAG(host);
1942 SURFXML_END_TAG(host);
1944 XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->V_peer_coord);
1945 SURFXML_BUFFER_SET(router_id, router_id);
1946 SURFXML_BUFFER_SET(router_coordinates, struct_peer->V_peer_coord);
1947 SURFXML_START_TAG(router);
1948 SURFXML_END_TAG(router);
1950 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, struct_peer->V_peer_bw_in, struct_peer->V_peer_lat);
1951 A_surfxml_link_state = A_surfxml_link_state_ON;
1952 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1953 SURFXML_BUFFER_SET(link_id, link_id_up);
1954 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_in);
1955 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1956 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1957 SURFXML_BUFFER_SET(link_latency_file, "");
1958 SURFXML_BUFFER_SET(link_state_file, "");
1959 SURFXML_START_TAG(link);
1960 SURFXML_END_TAG(link);
1962 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, struct_peer->V_peer_bw_out, struct_peer->V_peer_lat);
1963 A_surfxml_link_state = A_surfxml_link_state_ON;
1964 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1965 SURFXML_BUFFER_SET(link_id, link_id_down);
1966 SURFXML_BUFFER_SET(link_bandwidth, struct_peer->V_peer_bw_out);
1967 SURFXML_BUFFER_SET(link_latency, struct_peer->V_peer_lat);
1968 SURFXML_BUFFER_SET(link_bandwidth_file, "");
1969 SURFXML_BUFFER_SET(link_latency_file, "");
1970 SURFXML_BUFFER_SET(link_state_file, "");
1971 SURFXML_START_TAG(link);
1972 SURFXML_END_TAG(link);
1977 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
1978 XBT_DEBUG("symmetrical=\"NO\">");
1979 SURFXML_BUFFER_SET(route_src, host_id);
1980 SURFXML_BUFFER_SET(route_dst, router_id);
1981 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1982 SURFXML_START_TAG(route);
1984 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
1985 SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
1986 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1987 SURFXML_START_TAG(link_ctn);
1988 SURFXML_END_TAG(link_ctn);
1990 XBT_DEBUG("</route>");
1991 SURFXML_END_TAG(route);
1994 XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
1995 XBT_DEBUG("symmetrical=\"NO\">");
1996 SURFXML_BUFFER_SET(route_src, router_id);
1997 SURFXML_BUFFER_SET(route_dst, host_id);
1998 A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1999 SURFXML_START_TAG(route);
2001 XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
2002 SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
2003 A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2004 SURFXML_START_TAG(link_ctn);
2005 SURFXML_END_TAG(link_ctn);
2007 XBT_DEBUG("</route>");
2008 SURFXML_END_TAG(route);
2011 SURFXML_END_TAG(AS);
2014 //xbt_dynar_free(&tab_elements_num);
2018 free(link_backbone);
2021 surfxml_bufferstack_pop(1);
2024 static void routing_parse_Srandom(void)
2026 double mean, std, min, max, seed;
2027 char *random_id = A_surfxml_random_id;
2028 char *random_radical = A_surfxml_random_radical;
2029 char *rd_name = NULL;
2031 surf_parse_get_double(&mean,A_surfxml_random_mean);
2032 surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2033 surf_parse_get_double(&min,A_surfxml_random_min);
2034 surf_parse_get_double(&max,A_surfxml_random_max);
2035 surf_parse_get_double(&seed,A_surfxml_random_seed);
2039 random_data_t random = xbt_new0(s_random_data_t, 1);
2042 xbt_dynar_t radical_elements;
2046 xbt_dynar_t radical_ends;
2048 random->generator = A_surfxml_random_generator;
2049 random->seed = seed;
2053 /* Check user stupidities */
2055 THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2057 THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2060 THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2063 /* normalize the mean and standard deviation before storing */
2064 random->mean = (mean - min) / (max - min);
2065 random->std = std / (max - min);
2067 if (random->mean * (1 - random->mean) < random->std * random->std)
2068 THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2069 random->mean, random->std);
2071 XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2081 if(xbt_dict_size(random_value)==0)
2082 random_value = xbt_dict_new();
2084 if(!strcmp(random_radical,""))
2086 res = random_generate(random);
2087 rd_value = bprintf("%f",res);
2088 xbt_dict_set(random_value, random_id, rd_value, free);
2092 radical_elements = xbt_str_split(random_radical, ",");
2093 xbt_dynar_foreach(radical_elements, iter, groups) {
2094 radical_ends = xbt_str_split(groups, "-");
2095 switch (xbt_dynar_length(radical_ends)) {
2097 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2098 res = random_generate(random);
2099 tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2100 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2104 case 2: surf_parse_get_int(&start,
2105 xbt_dynar_get_as(radical_ends, 0, char *));
2106 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2107 for (i = start; i <= end; i++) {
2108 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2109 res = random_generate(random);
2110 tmpbuf = bprintf("%s%d",random_id,i);
2111 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2116 XBT_INFO("Malformed radical");
2119 res = random_generate(random);
2120 rd_name = bprintf("%s_router",random_id);
2121 rd_value = bprintf("%f",res);
2122 xbt_dict_set(random_value, rd_name, rd_value, free);
2124 xbt_dynar_free(&radical_ends);
2127 xbt_dynar_free(&radical_elements);
2131 static void routing_parse_Erandom(void)
2133 /*xbt_dict_cursor_t cursor = NULL;
2137 xbt_dict_foreach(random_value, cursor, key, elem) {
2138 XBT_DEBUG("%s = %s",key,elem);
2144 * New methods to init the routing model component from the lua script
2149 * add a host to the network element list
2152 void routing_add_host(const char *host_id)
2154 parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2158 * Set a new link on the actual list of link for a route or ASroute
2160 void routing_add_link(const char *link_id)
2162 parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2166 *Set the endpoints for a route
2168 void routing_set_route(const char *src_id, const char *dst_id)
2170 parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2174 * Store the route by calling parse_E_route_store_route
2176 void routing_store_route(void)
2178 parse_E_route_store_route();