1 /* Copyright (c) 2009-2011, 2013-2015. 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 "surf_routing.hpp"
8 #include "surf_routing_private.hpp"
9 #include "surf_routing_cluster.hpp"
10 #include "surf_routing_cluster_torus.hpp"
11 #include "surf_routing_cluster_fat_tree.hpp"
13 #include "simgrid/platf_interface.h" // platform creation API internal interface
14 #include "simgrid/sg_config.h"
15 #include "storage_interface.hpp"
17 #include "surf/surfxml_parse_values.h"
26 surf_callback(void, simgrid::surf::RoutingEdge*) routingEdgeCreatedCallbacks;
27 surf_callback(void, simgrid::surf::As*) asCreatedCallbacks;
33 * @ingroup SURF_build_api
34 * @brief A library containing all known hosts
38 int SURF_HOST_LEVEL; //Surf host level
39 int COORD_HOST_LEVEL=0; //Coordinates level
40 int NS3_HOST_LEVEL; //host node for ns3
42 int MSG_FILE_LEVEL; //Msg file level
44 int SIMIX_STORAGE_LEVEL; //Simix storage level
45 int MSG_STORAGE_LEVEL; //Msg storage level
46 int SD_STORAGE_LEVEL; //Simdag storage level
48 xbt_lib_t as_router_lib;
49 int ROUTING_ASR_LEVEL; //Routing level
50 int COORD_ASR_LEVEL; //Coordinates level
51 int NS3_ASR_LEVEL; //host node for ns3
52 int ROUTING_PROP_ASR_LEVEL; //Where the properties are stored
54 static xbt_dict_t random_value = NULL;
57 /** @brief Retrieve a routing edge from its name
59 * Routing edges are either host and routers, whatever
61 simgrid::surf::RoutingEdge *sg_routing_edge_by_name_or_null(const char *name)
63 sg_host_t h = sg_host_by_name(name);
64 simgrid::surf::RoutingEdge *net_elm = h==NULL?NULL: sg_host_edge(h);
66 net_elm = (simgrid::surf::RoutingEdge*) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
71 simgrid::surf::RoutingPlatf *routing_platf = NULL;
73 /* global parse functions */
74 extern xbt_dynar_t mount_list;
76 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
78 /** The current AS in the parsing */
79 static simgrid::surf::As *current_routing = NULL;
80 simgrid::surf::As* routing_get_current()
82 return current_routing;
85 // static void routing_parse_Srandom(void); /* random bypass */
87 static void routing_parse_postparse(void);
89 /* this lines are only for replace use like index in the model table */
94 SURF_MODEL_DIJKSTRACACHE,
98 SURF_MODEL_TORUS_CLUSTER,
99 SURF_MODEL_FAT_TREE_CLUSTER,
102 struct s_model_type routing_models[] = {
104 "Full routing data (fast, large memory requirements, fully expressive)",
105 model_full_create, model_full_end},
107 "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
108 model_floyd_create, model_floyd_end},
110 "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
111 model_dijkstra_create, model_dijkstra_both_end},
113 "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
114 model_dijkstracache_create, model_dijkstra_both_end},
115 {"none", "No routing (Unless you know what you are doing, avoid using this mode in combination with a non Constant network model).",
116 model_none_create, NULL},
117 {"Vivaldi", "Vivaldi routing",
118 model_vivaldi_create, NULL},
119 {"Cluster", "Cluster routing",
120 model_cluster_create, NULL},
121 {"Torus_Cluster", "Torus Cluster routing",
122 model_torus_cluster_create, NULL},
123 {"Fat_Tree_Cluster", "Fat Tree Cluster routing",
124 model_fat_tree_cluster_create, NULL},
125 {NULL, NULL, NULL, NULL}
129 * \brief Add a "host_link" to the network element list
131 void sg_platf_new_host_link(sg_platf_host_link_cbarg_t host)
133 simgrid::surf::RoutingEdge *info = sg_host_edge(sg_host_by_name(host->id));
134 xbt_assert(info, "Host '%s' not found!", host->id);
135 xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] ||
136 current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI],
137 "You have to be in model Cluster to use tag host_link!");
139 s_surf_parsing_link_up_down_t link_up_down;
140 link_up_down.link_up = Link::byName(host->link_up);
141 link_up_down.link_down = Link::byName(host->link_down);
143 xbt_assert(link_up_down.link_up, "Link '%s' not found!",host->link_up);
144 xbt_assert(link_up_down.link_down, "Link '%s' not found!",host->link_down);
146 if(!current_routing->p_linkUpDownList)
147 current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
149 // If dynar is is greater than edge id and if the host_link is already defined
150 if((int)xbt_dynar_length(current_routing->p_linkUpDownList) > info->getId() &&
151 xbt_dynar_get_as(current_routing->p_linkUpDownList, info->getId(), void*))
152 surf_parse_error("Host_link for '%s' is already defined!",host->id);
154 XBT_DEBUG("Push Host_link for host '%s' to position %d", info->getName(), info->getId());
155 xbt_dynar_set_as(current_routing->p_linkUpDownList, info->getId(), s_surf_parsing_link_up_down_t, link_up_down);
159 * \brief Add a "host" to the network element list
161 simgrid::surf::RoutingEdge *routing_add_host(
162 simgrid::surf::As* current_routing, sg_platf_host_cbarg_t host)
164 if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
165 current_routing->p_hierarchy = SURF_ROUTING_BASE;
166 xbt_assert(!sg_host_by_name(host->id),
167 "Reading a host, processing unit \"%s\" already exists", host->id);
169 simgrid::surf::RoutingEdge *routingEdge =
170 new simgrid::surf::RoutingEdgeImpl(xbt_strdup(host->id),
172 SURF_NETWORK_ELEMENT_HOST,
174 routingEdge->setId(current_routing->parsePU(routingEdge));
175 sg_host_edge_set(sg_host_by_name_or_create(host->id), routingEdge);
176 XBT_DEBUG("Having set name '%s' id '%d'", host->id, routingEdge->getId());
177 simgrid::surf::routingEdgeCreatedCallbacks(routingEdge);
180 xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list);
184 if (host->coord && strcmp(host->coord, "")) {
188 if (!COORD_HOST_LEVEL)
189 xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
190 /* Pre-parse the host coordinates -- FIXME factorize with routers by overloading the routing->parse_PU function*/
191 xbt_dynar_t ctn_str = xbt_str_split_str(host->coord, " ");
192 xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
193 xbt_dynar_foreach(ctn_str,cursor, str) {
194 double val = atof(str);
195 xbt_dynar_push(ctn,&val);
197 xbt_dynar_shrink(ctn, 0);
198 xbt_dynar_free(&ctn_str);
199 xbt_lib_set(host_lib, host->id, COORD_HOST_LEVEL, (void *) ctn);
200 XBT_DEBUG("Having set host coordinates for '%s'",host->id);
207 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
209 static void parse_E_ASroute(sg_platf_route_cbarg_t ASroute)
211 /*FIXME:REMOVE:xbt_assert(current_routing->parse_ASroute,
212 "no defined method \"set_ASroute\" in \"%s\"",
213 current_routing->name);*/
214 current_routing->parseASroute(ASroute);
217 void sg_platf_new_trace(sg_platf_trace_cbarg_t trace)
219 tmgr_trace_t tmgr_trace;
220 if (!trace->file || strcmp(trace->file, "") != 0) {
221 tmgr_trace = tmgr_trace_new_from_file(trace->file);
222 } else if (strcmp(trace->pc_data, "") == 0) {
226 tmgr_trace_new_from_string(trace->id, trace->pc_data,
229 xbt_dict_set(traces_set_list, trace->id, (void *) tmgr_trace, NULL);
232 void sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect)
234 xbt_assert(xbt_dict_get_or_null
235 (traces_set_list, trace_connect->trace),
236 "Cannot connect trace %s to %s: trace unknown",
237 trace_connect->trace,
238 trace_connect->element);
240 switch (trace_connect->kind) {
241 case SURF_TRACE_CONNECT_KIND_HOST_AVAIL:
242 xbt_dict_set(trace_connect_list_host_avail,
243 trace_connect->trace,
244 xbt_strdup(trace_connect->element), NULL);
246 case SURF_TRACE_CONNECT_KIND_POWER:
247 xbt_dict_set(trace_connect_list_power, trace_connect->trace,
248 xbt_strdup(trace_connect->element), NULL);
250 case SURF_TRACE_CONNECT_KIND_LINK_AVAIL:
251 xbt_dict_set(trace_connect_list_link_avail,
252 trace_connect->trace,
253 xbt_strdup(trace_connect->element), NULL);
255 case SURF_TRACE_CONNECT_KIND_BANDWIDTH:
256 xbt_dict_set(trace_connect_list_bandwidth,
257 trace_connect->trace,
258 xbt_strdup(trace_connect->element), NULL);
260 case SURF_TRACE_CONNECT_KIND_LATENCY:
261 xbt_dict_set(trace_connect_list_latency, trace_connect->trace,
262 xbt_strdup(trace_connect->element), NULL);
265 surf_parse_error("Cannot connect trace %s to %s: kind of trace unknown",
266 trace_connect->trace, trace_connect->element);
272 * \brief Make a new routing component to the platform
274 * Add a new autonomous system to the platform. Any elements (such as host,
275 * router or sub-AS) added after this call and before the corresponding call
276 * to sg_platf_new_AS_close() will be added to this AS.
278 * Once this function was called, the configuration concerning the used
279 * models cannot be changed anymore.
281 * @param AS_id name of this autonomous system. Must be unique in the platform
282 * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
284 void routing_AS_begin(sg_platf_AS_cbarg_t AS)
286 XBT_DEBUG("routing_AS_begin");
287 routing_model_description_t model = NULL;
289 xbt_assert(!xbt_lib_get_or_null
290 (as_router_lib, AS->id, ROUTING_ASR_LEVEL),
291 "The AS \"%s\" already exists", AS->id);
293 _sg_cfg_init_status = 2; /* horrible hack: direct access to the global
294 * controlling the level of configuration to prevent
295 * any further config */
297 /* search the routing model */
299 case A_surfxml_AS_routing_Cluster: model = &routing_models[SURF_MODEL_CLUSTER];break;
300 case A_surfxml_AS_routing_Cluster___torus: model = &routing_models[SURF_MODEL_TORUS_CLUSTER];break;
301 case A_surfxml_AS_routing_Cluster___fat___tree: model = &routing_models[SURF_MODEL_FAT_TREE_CLUSTER];break;
302 case A_surfxml_AS_routing_Dijkstra: model = &routing_models[SURF_MODEL_DIJKSTRA];break;
303 case A_surfxml_AS_routing_DijkstraCache: model = &routing_models[SURF_MODEL_DIJKSTRACACHE];break;
304 case A_surfxml_AS_routing_Floyd: model = &routing_models[SURF_MODEL_FLOYD];break;
305 case A_surfxml_AS_routing_Full: model = &routing_models[SURF_MODEL_FULL];break;
306 case A_surfxml_AS_routing_None: model = &routing_models[SURF_MODEL_NONE];break;
307 case A_surfxml_AS_routing_Vivaldi: model = &routing_models[SURF_MODEL_VIVALDI];break;
308 default: xbt_die("Not a valid model!!!");
312 /* make a new routing component */
313 simgrid::surf::As *new_as = model->create();
315 new_as->p_modelDesc = model;
316 new_as->p_hierarchy = SURF_ROUTING_NULL;
317 new_as->p_name = xbt_strdup(AS->id);
319 simgrid::surf::RoutingEdge *info =
320 new simgrid::surf::RoutingEdgeImpl(xbt_strdup(new_as->p_name),
322 SURF_NETWORK_ELEMENT_AS,
324 if (current_routing == NULL && routing_platf->p_root == NULL) {
326 /* it is the first one */
327 new_as->p_routingFather = NULL;
328 routing_platf->p_root = new_as;
330 } else if (current_routing != NULL && routing_platf->p_root != NULL) {
332 xbt_assert(!xbt_dict_get_or_null
333 (current_routing->p_routingSons, AS->id),
334 "The AS \"%s\" already exists", AS->id);
335 /* it is a part of the tree */
336 new_as->p_routingFather = current_routing;
337 /* set the father behavior */
338 if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
339 current_routing->p_hierarchy = SURF_ROUTING_RECURSIVE;
340 /* add to the sons dictionary */
341 xbt_dict_set(current_routing->p_routingSons, AS->id,
342 (void *) new_as, NULL);
343 /* add to the father element list */
344 info->setId(current_routing->parseAS(info));
346 THROWF(arg_error, 0, "All defined components must belong to a AS");
349 xbt_lib_set(as_router_lib, info->getName(), ROUTING_ASR_LEVEL,
351 XBT_DEBUG("Having set name '%s' id '%d'", new_as->p_name, info->getId());
353 /* set the new current component of the tree */
354 current_routing = new_as;
355 current_routing->p_netElem = info;
357 simgrid::surf::routingEdgeCreatedCallbacks(info);
358 simgrid::surf::asCreatedCallbacks(new_as);
362 * \brief Specify that the current description of AS is finished
364 * Once you've declared all the content of your AS, you have to close
365 * it with this call. Your AS is not usable until you call this function.
367 * @fixme: this call is not as robust as wanted: bad things WILL happen
368 * if you call it twice for the same AS, or if you forget calling it, or
369 * even if you add stuff to a closed AS
372 void routing_AS_end()
375 if (current_routing == NULL) {
376 THROWF(arg_error, 0, "Close an AS, but none was under construction");
378 if (current_routing->p_modelDesc->end)
379 current_routing->p_modelDesc->end(current_routing);
380 current_routing = current_routing->p_routingFather;
384 /* Aux Business methods */
387 * \brief Get the AS father and the first elements of the chain
389 * \param src the source host name
390 * \param dst the destination host name
392 * Get the common father of the to processing units, and the first different
393 * father in the chain
395 static void elements_father(sg_routing_edge_t src, sg_routing_edge_t dst,
400 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
401 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
402 simgrid::surf::As *src_as, *dst_as;
403 simgrid::surf::As *path_src[ELEMENTS_FATHER_MAXDEPTH];
404 simgrid::surf::As *path_dst[ELEMENTS_FATHER_MAXDEPTH];
407 simgrid::surf::As *current;
408 simgrid::surf::As *current_src;
409 simgrid::surf::As *current_dst;
410 simgrid::surf::As *father;
412 /* (1) find the as where the src and dst are located */
413 sg_routing_edge_t src_data = src;
414 sg_routing_edge_t dst_data = dst;
415 src_as = src_data->getRcComponent();
416 dst_as = dst_data->getRcComponent();
418 char* src_name = src_data->getName();
419 char* dst_name = dst_data->getName();
422 xbt_assert(src_as && dst_as,
423 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src_name, dst_name);
425 /* (2) find the path to the root routing component */
426 for (current = src_as; current != NULL; current = current->p_routingFather) {
427 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
428 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
429 path_src[index_src++] = current;
431 for (current = dst_as; current != NULL; current = current->p_routingFather) {
432 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
433 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
434 path_dst[index_dst++] = current;
437 /* (3) find the common father */
439 current_src = path_src[--index_src];
440 current_dst = path_dst[--index_dst];
441 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
443 /* (4) they are not in the same routing component, make the path */
444 if (current_src == current_dst)
445 father = current_src;
447 father = path_src[index_src + 1];
449 /* (5) result generation */
450 *res_father = father; /* first the common father of src and dst */
451 *res_src = current_src; /* second the first different father of src */
452 *res_dst = current_dst; /* three the first different father of dst */
454 #undef ELEMENTS_FATHER_MAXDEPTH
457 /* Global Business methods */
460 * \brief Recursive function for get_route_latency
462 * \param src the source host name
463 * \param dst the destination host name
464 * \param *route the route where the links are stored. It is either NULL or a ready to use dynar
465 * \param *latency the latency, if needed
467 * This function is called by "get_route" and "get_latency". It allows to walk
468 * recursively through the ASes tree.
470 static void _get_route_and_latency(
471 simgrid::surf::RoutingEdge *src, simgrid::surf::RoutingEdge *dst,
472 xbt_dynar_t * links, double *latency)
474 s_sg_platf_route_cbarg_t route = SG_PLATF_ROUTE_INITIALIZER;
475 memset(&route,0,sizeof(route));
477 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
478 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src->getName(), dst->getName());
480 /* Find how src and dst are interconnected */
481 simgrid::surf::As *common_father, *src_father, *dst_father;
482 elements_father(src, dst, &common_father, &src_father, &dst_father);
483 XBT_DEBUG("elements_father: common father '%s' src_father '%s' dst_father '%s'",
484 common_father->p_name, src_father->p_name, dst_father->p_name);
486 /* Check whether a direct bypass is defined */
487 sg_platf_route_cbarg_t e_route_bypass = NULL;
488 //FIXME:REMOVE:if (common_father->get_bypass_route)
490 e_route_bypass = common_father->getBypassRoute(src, dst, latency);
492 /* Common ancestor is kind enough to declare a bypass route from src to dst -- use it and bail out */
493 if (e_route_bypass) {
494 xbt_dynar_merge(links, &e_route_bypass->link_list);
495 generic_free_route(e_route_bypass);
499 /* If src and dst are in the same AS, life is good */
500 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
501 route.link_list = *links;
502 common_father->getRouteAndLatency(src, dst, &route, latency);
503 // if vivaldi latency+=vivaldi(src,dst)
507 /* Not in the same AS, no bypass. We'll have to find our path between the ASes recursively*/
509 route.link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
510 // Find the net_card corresponding to father
511 simgrid::surf::RoutingEdge *src_father_net_elm = src_father->p_netElem;
512 simgrid::surf::RoutingEdge *dst_father_net_elm = dst_father->p_netElem;
514 common_father->getRouteAndLatency(src_father_net_elm, dst_father_net_elm,
517 xbt_assert((route.gw_src != NULL) && (route.gw_dst != NULL),
518 "bad gateways for route from \"%s\" to \"%s\"", src->getName(), dst->getName());
520 sg_routing_edge_t src_gateway_net_elm = route.gw_src;
521 sg_routing_edge_t dst_gateway_net_elm = route.gw_dst;
523 /* If source gateway is not our source, we have to recursively find our way up to this point */
524 if (src != src_gateway_net_elm)
525 _get_route_and_latency(src, src_gateway_net_elm, links, latency);
526 xbt_dynar_merge(links, &route.link_list);
528 /* If dest gateway is not our destination, we have to recursively find our way from this point */
529 if (dst_gateway_net_elm != dst)
530 _get_route_and_latency(dst_gateway_net_elm, dst, links, latency);
532 // if vivaldi latency+=vivaldi(src_gateway,dst_gateway)
535 AS_t surf_platf_get_root(routing_platf_t platf){
536 return platf->p_root;
539 e_surf_network_element_type_t surf_routing_edge_get_rc_type(sg_routing_edge_t edge){
540 return edge->getRcType();
547 * \brief Find a route between hosts
549 * \param src the network_element_t for src host
550 * \param dst the network_element_t for dst host
551 * \param route where to store the list of links.
552 * If *route=NULL, create a short lived dynar. Else, fill the provided dynar
553 * \param latency where to store the latency experienced on the path (or NULL if not interested)
554 * It is the caller responsability to initialize latency to 0 (we add to provided route)
557 * walk through the routing components tree and find a route between hosts
558 * by calling the differents "get_route" functions in each routing component.
560 void RoutingPlatf::getRouteAndLatency(
561 simgrid::surf::RoutingEdge *src, simgrid::surf::RoutingEdge *dst,
562 xbt_dynar_t* route, double *latency)
564 XBT_DEBUG("routing_get_route_and_latency from %s to %s", src->getName(), dst->getName());
566 xbt_dynar_reset(routing_platf->p_lastRoute);
567 *route = routing_platf->p_lastRoute;
570 _get_route_and_latency(src, dst, route, latency);
572 xbt_assert(!latency || *latency >= 0.0,
573 "negative latency on route between \"%s\" and \"%s\"", src->getName(), dst->getName());
576 xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
577 return recursiveGetOneLinkRoutes(p_root);
580 xbt_dynar_t RoutingPlatf::recursiveGetOneLinkRoutes(As *rc)
582 xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
584 //adding my one link routes
585 xbt_dynar_t onelink_mine = rc->getOneLinkRoutes();
587 xbt_dynar_merge(&ret,&onelink_mine);
591 xbt_dict_cursor_t cursor = NULL;
593 xbt_dict_foreach(rc->p_routingSons, cursor, key, rc_child) {
594 xbt_dynar_t onelink_child = recursiveGetOneLinkRoutes(rc_child);
596 xbt_dynar_merge(&ret,&onelink_child);
604 e_surf_network_element_type_t routing_get_network_element_type(const char *name)
606 simgrid::surf::RoutingEdge *rc = sg_routing_edge_by_name_or_null(name);
608 return rc->getRcType();
610 return SURF_NETWORK_ELEMENT_NULL;
614 * \brief Generic method: create the global routing schema
616 * Make a global routing structure and set all the parsing functions.
618 void routing_model_create( void *loopback)
620 /* config the uniq global routing */
621 routing_platf = new simgrid::surf::RoutingPlatf();
622 routing_platf->p_root = NULL;
623 routing_platf->p_loopback = loopback;
624 routing_platf->p_lastRoute = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
625 /* no current routing at moment */
626 current_routing = NULL;
630 /* ************************************************** */
631 /* ********** PATERN FOR NEW ROUTING **************** */
633 /* The minimal configuration of a new routing model need the next functions,
634 * also you need to set at the start of the file, the new model in the model
635 * list. Remember keep the null ending of the list.
637 /*** Routing model structure ***/
639 // s_routing_component_t generic_routing;
640 // /* things that your routing model need */
641 // } s_routing_component_NEW_t,*routing_component_NEW_t;
643 /*** Parse routing model functions ***/
644 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
645 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
646 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
647 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
648 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
650 /*** Business methods ***/
651 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
652 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
653 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
655 /*** Creation routing model functions ***/
656 // static void* model_NEW_create(void) {
657 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
658 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
659 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
660 // new_component->generic_routing.set_route = model_NEW_set_route;
661 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
662 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
663 // new_component->generic_routing.get_route = NEW_get_route;
664 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
665 // new_component->generic_routing.finalize = NEW_finalize;
666 // /* initialization of internal structures */
667 // return new_component;
669 // static void model_NEW_load(void) {} /* mandatory */
670 // static void model_NEW_unload(void) {} /* mandatory */
671 // static void model_NEW_end(void) {} /* mandatory */
673 /* ************************************************************************** */
674 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
676 void routing_cluster_add_backbone(void* bb) {
677 xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER],
678 "You have to be in model Cluster to use tag backbone!");
679 xbt_assert(!static_cast<simgrid::surf::AsCluster*>(current_routing)->p_backbone, "The backbone link is already defined!");
680 static_cast<simgrid::surf::AsCluster*>(current_routing)->p_backbone =
681 static_cast<simgrid::surf::Link*>(bb);
682 XBT_DEBUG("Add a backbone to AS '%s'", current_routing->p_name);
685 void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
688 char *groups , *host_id , *link_id = NULL;
690 xbt_dynar_t radical_elements;
691 xbt_dynar_t radical_ends;
694 radical_elements = xbt_str_split(cabinet->radical, ",");
695 xbt_dynar_foreach(radical_elements, iter, groups) {
697 radical_ends = xbt_str_split(groups, "-");
698 start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
700 switch (xbt_dynar_length(radical_ends)) {
705 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
708 surf_parse_error("Malformed radical");
711 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
712 memset(&host, 0, sizeof(host));
713 host.initial_state = SURF_RESOURCE_ON;
715 host.speed_scale = 1.0;
716 host.core_amount = 1;
718 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
719 memset(&link, 0, sizeof(link));
720 link.state = SURF_RESOURCE_ON;
721 link.policy = SURF_LINK_FULLDUPLEX;
722 link.latency = cabinet->lat;
723 link.bandwidth = cabinet->bw;
725 s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
726 memset(&host_link, 0, sizeof(host_link));
728 for (i = start; i <= end; i++) {
729 host_id = bprintf("%s%d%s",cabinet->prefix,i,cabinet->suffix);
730 link_id = bprintf("link_%s%d%s",cabinet->prefix,i,cabinet->suffix);
733 host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
734 xbt_dynar_push(host.speed_peak,&cabinet->speed);
735 sg_platf_new_host(&host);
736 xbt_dynar_free(&host.speed_peak);
737 sg_platf_new_link(&link);
739 char* link_up = bprintf("%s_UP",link_id);
740 char* link_down = bprintf("%s_DOWN",link_id);
741 host_link.id = host_id;
742 host_link.link_up = link_up;
743 host_link.link_down = link_down;
744 sg_platf_new_host_link(&host_link);
752 xbt_dynar_free(&radical_ends);
754 xbt_dynar_free(&radical_elements);
757 void routing_new_cluster(sg_platf_cluster_cbarg_t cluster)
759 using simgrid::surf::AsCluster;
760 using simgrid::surf::AsClusterTorus;
761 using simgrid::surf::AsClusterFatTree;
763 char *host_id, *groups, *link_id = NULL;
764 xbt_dict_t patterns = NULL;
767 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
768 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
772 xbt_dynar_t radical_elements;
773 xbt_dynar_t radical_ends;
775 if ((cluster->availability_trace && strcmp(cluster->availability_trace, ""))
776 || (cluster->state_trace && strcmp(cluster->state_trace, ""))) {
777 patterns = xbt_dict_new_homogeneous(xbt_free_f);
778 xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), NULL);
779 xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), NULL);
780 xbt_dict_set(patterns, "suffix", xbt_strdup(cluster->suffix), NULL);
783 /* parse the topology attribute. If we are not in a flat cluster,
784 * switch to the right mode and initialize the routing with
785 * the parameters in topo_parameters attribute
787 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
790 if(cluster->topology == SURF_CLUSTER_TORUS){
791 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Torus_Cluster\">", cluster->id);
792 AS.routing = A_surfxml_AS_routing_Cluster___torus;
793 sg_platf_new_AS_begin(&AS);
794 ((AsClusterTorus*)current_routing)->parse_specific_arguments(cluster);
796 else if (cluster->topology == SURF_CLUSTER_FAT_TREE) {
797 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Fat_Tree_Cluster\">", cluster->id);
798 AS.routing = A_surfxml_AS_routing_Cluster___fat___tree;
799 sg_platf_new_AS_begin(&AS);
800 ((AsClusterFatTree*)current_routing)->parse_specific_arguments(cluster);
804 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", cluster->id);
805 AS.routing = A_surfxml_AS_routing_Cluster;
806 sg_platf_new_AS_begin(&AS);
809 if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
810 ((AsCluster*)current_routing)->p_nb_links_per_node++;
811 ((AsCluster*)current_routing)->p_has_loopback=1;
814 if(cluster->limiter_link!=0){
815 ((AsCluster*)current_routing)->p_nb_links_per_node++;
816 ((AsCluster*)current_routing)->p_has_limiter=1;
821 current_routing->p_linkUpDownList
822 = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
825 radical_elements = xbt_str_split(cluster->radical, ",");
826 xbt_dynar_foreach(radical_elements, iter, groups) {
828 radical_ends = xbt_str_split(groups, "-");
829 start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
831 switch (xbt_dynar_length(radical_ends)) {
836 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
839 surf_parse_error("Malformed radical");
842 for (i = start; i <= end; i++) {
844 bprintf("%s%d%s", cluster->prefix, i, cluster->suffix);
845 link_id = bprintf("%s_link_%d", cluster->id, i);
847 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, cluster->speed);
849 memset(&host, 0, sizeof(host));
851 if ((cluster->properties != NULL) && (!xbt_dict_is_empty(cluster->properties))) {
852 xbt_dict_cursor_t cursor=NULL;
854 host.properties = xbt_dict_new();
856 xbt_dict_foreach(cluster->properties,cursor,key,data) {
857 xbt_dict_set(host.properties, key, xbt_strdup(data),free);
860 if (cluster->availability_trace && strcmp(cluster->availability_trace, "")) {
861 xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
862 char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
863 XBT_DEBUG("\tavailability_file=\"%s\"", avail_file);
864 host.speed_trace = tmgr_trace_new_from_file(avail_file);
865 xbt_free(avail_file);
867 XBT_DEBUG("\tavailability_file=\"\"");
870 if (cluster->state_trace && strcmp(cluster->state_trace, "")) {
871 char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns);
872 XBT_DEBUG("\tstate_file=\"%s\"", avail_file);
873 host.state_trace = tmgr_trace_new_from_file(avail_file);
874 xbt_free(avail_file);
876 XBT_DEBUG("\tstate_file=\"\"");
879 host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
880 xbt_dynar_push(host.speed_peak,&cluster->speed);
883 //host.power_peak = cluster->power;
884 host.speed_scale = 1.0;
885 host.core_amount = cluster->core_amount;
886 host.initial_state = SURF_RESOURCE_ON;
888 sg_platf_new_host(&host);
889 xbt_dynar_free(&host.speed_peak);
890 XBT_DEBUG("</host>");
892 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,
893 cluster->bw, cluster->lat);
896 s_surf_parsing_link_up_down_t info_lim, info_loop;
897 // All links are saved in a matrix;
898 // every row describes a single node; every node
899 // may have multiple links.
900 // the first column may store a link from x to x if p_has_loopback is set
901 // the second column may store a limiter link if p_has_limiter is set
902 // other columns are to store one or more link for the node
904 //add a loopback link
905 if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
906 char *tmp_link = bprintf("%s_loopback", link_id);
907 XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link,
908 cluster->limiter_link);
911 memset(&link, 0, sizeof(link));
913 link.bandwidth = cluster->loopback_bw;
914 link.latency = cluster->loopback_lat;
915 link.state = SURF_RESOURCE_ON;
916 link.policy = SURF_LINK_FATPIPE;
917 sg_platf_new_link(&link);
918 info_loop.link_up = Link::byName(tmp_link);
919 info_loop.link_down = info_loop.link_up;
921 xbt_dynar_set(current_routing->p_linkUpDownList,
922 rankId*(static_cast<AsCluster*>(current_routing))->p_nb_links_per_node, &info_loop);
925 //add a limiter link (shared link to account for maximal bandwidth of the node)
926 if(cluster->limiter_link!=0){
927 char *tmp_link = bprintf("%s_limiter", link_id);
928 XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link,
929 cluster->limiter_link);
932 memset(&link, 0, sizeof(link));
934 link.bandwidth = cluster->limiter_link;
936 link.state = SURF_RESOURCE_ON;
937 link.policy = SURF_LINK_SHARED;
938 sg_platf_new_link(&link);
939 info_lim.link_up = Link::byName(tmp_link);
940 info_lim.link_down = info_lim.link_up;
942 auto as_cluster = static_cast<AsCluster*>(current_routing);
943 xbt_dynar_set(current_routing->p_linkUpDownList,
944 rankId*(as_cluster)->p_nb_links_per_node + as_cluster->p_has_loopback ,
950 //call the cluster function that adds the others links
951 if (cluster->topology == SURF_CLUSTER_FAT_TREE) {
952 ((AsClusterFatTree*) current_routing)->addProcessingNode(i);
955 static_cast<AsCluster*>(current_routing)->create_links_for_node(cluster, i, rankId, rankId*
956 static_cast<AsCluster*>(current_routing)->p_nb_links_per_node
957 + static_cast<AsCluster*>(current_routing)->p_has_loopback
958 + static_cast<AsCluster*>(current_routing)->p_has_limiter );
965 xbt_dynar_free(&radical_ends);
967 xbt_dynar_free(&radical_elements);
969 // For fat trees, the links must be created once all nodes have been added
970 if(cluster->topology == SURF_CLUSTER_FAT_TREE) {
971 static_cast<simgrid::surf::AsClusterFatTree*>(current_routing)->create_links();
973 // Add a router. It is magically used thanks to the way in which surf_routing_cluster is written,
974 // and it's very useful to connect clusters together
976 XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id);
978 s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
979 memset(&router, 0, sizeof(router));
980 router.id = cluster->router_id;
982 if (!router.id || !strcmp(router.id, ""))
984 bprintf("%s%s_router%s", cluster->prefix, cluster->id,
986 sg_platf_new_router(&router);
987 ((AsCluster*)current_routing)->p_router = (simgrid::surf::RoutingEdge*) xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL);
991 if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
992 char *link_backbone = bprintf("%s_backbone", cluster->id);
993 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,
994 cluster->bb_bw, cluster->bb_lat);
996 memset(&link, 0, sizeof(link));
997 link.id = link_backbone;
998 link.bandwidth = cluster->bb_bw;
999 link.latency = cluster->bb_lat;
1000 link.state = SURF_RESOURCE_ON;
1001 link.policy = cluster->bb_sharing_policy;
1003 sg_platf_new_link(&link);
1005 routing_cluster_add_backbone(Link::byName(link_backbone));
1007 free(link_backbone);
1011 sg_platf_new_AS_end();
1013 xbt_dict_free(&patterns); // no op if it were never set
1016 static void routing_parse_postparse(void) {
1017 xbt_dict_free(&random_value);
1020 void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
1022 using simgrid::surf::RoutingEdge;
1023 using simgrid::surf::AsCluster;
1025 char *host_id = NULL;
1026 char *link_id = NULL;
1027 char *router_id = NULL;
1030 host_id = HOST_PEER(peer->id);
1031 link_id = LINK_PEER(peer->id);
1032 router_id = ROUTER_PEER(peer->id);
1034 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", peer->id);
1035 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
1037 AS.routing = A_surfxml_AS_routing_Cluster;
1038 sg_platf_new_AS_begin(&AS);
1040 current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
1042 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->speed);
1043 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
1044 memset(&host, 0, sizeof(host));
1045 host.initial_state = SURF_RESOURCE_ON;
1048 host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
1049 xbt_dynar_push(host.speed_peak,&peer->speed);
1051 //host.power_peak = peer->power;
1052 host.speed_scale = 1.0;
1053 host.speed_trace = peer->availability_trace;
1054 host.state_trace = peer->state_trace;
1055 host.core_amount = 1;
1056 sg_platf_new_host(&host);
1057 xbt_dynar_free(&host.speed_peak);
1059 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
1060 memset(&link, 0, sizeof(link));
1061 link.state = SURF_RESOURCE_ON;
1062 link.policy = SURF_LINK_SHARED;
1063 link.latency = peer->lat;
1065 char* link_up = bprintf("%s_UP",link_id);
1066 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_up,
1067 peer->bw_out, peer->lat);
1069 link.bandwidth = peer->bw_out;
1070 sg_platf_new_link(&link);
1072 char* link_down = bprintf("%s_DOWN",link_id);
1073 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_down,
1074 peer->bw_in, peer->lat);
1075 link.id = link_down;
1076 link.bandwidth = peer->bw_in;
1077 sg_platf_new_link(&link);
1079 XBT_DEBUG("<host_link\tid=\"%s\"\tup=\"%s\"\tdown=\"%s\" />", host_id,link_up,link_down);
1080 s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
1081 memset(&host_link, 0, sizeof(host_link));
1082 host_link.id = host_id;
1083 host_link.link_up = link_up;
1084 host_link.link_down = link_down;
1085 sg_platf_new_host_link(&host_link);
1087 XBT_DEBUG("<router id=\"%s\"/>", router_id);
1088 s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
1089 memset(&router, 0, sizeof(router));
1090 router.id = router_id;
1091 router.coord = peer->coord;
1092 sg_platf_new_router(&router);
1093 static_cast<AsCluster*>(current_routing)->p_router = static_cast<RoutingEdge*>(xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL));
1096 sg_platf_new_AS_end();
1099 //xbt_dynar_free(&tab_elements_num);
1107 // static void routing_parse_Srandom(void)
1109 // double mean, std, min, max, seed;
1110 // char *random_id = A_surfxml_random_id;
1111 // char *random_radical = A_surfxml_random_radical;
1112 // char *rd_name = NULL;
1114 // mean = surf_parse_get_double(A_surfxml_random_mean);
1115 // std = surf_parse_get_double(A_surfxml_random_std___deviation);
1116 // min = surf_parse_get_double(A_surfxml_random_min);
1117 // max = surf_parse_get_double(A_surfxml_random_max);
1118 // seed = surf_parse_get_double(A_surfxml_random_seed);
1122 // random_data_t random = xbt_new0(s_random_data_t, 1);
1125 // xbt_dynar_t radical_elements;
1126 // unsigned int iter;
1129 // xbt_dynar_t radical_ends;
1131 // switch (A_surfxml_random_generator) {
1132 // case AU_surfxml_random_generator:
1133 // case A_surfxml_random_generator_NONE:
1134 // random->generator = NONE;
1136 // case A_surfxml_random_generator_DRAND48:
1137 // random->generator = DRAND48;
1139 // case A_surfxml_random_generator_RAND:
1140 // random->generator = RAND;
1142 // case A_surfxml_random_generator_RNGSTREAM:
1143 // random->generator = RNGSTREAM;
1146 // surf_parse_error("Invalid random generator");
1149 // random->seed = seed;
1150 // random->min = min;
1151 // random->max = max;
1153 // /* Check user stupidities */
1155 // THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
1157 // THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean, min);
1159 // THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean, max);
1161 // /* normalize the mean and standard deviation before storing */
1162 // random->mean = (mean - min) / (max - min);
1163 // random->std = std / (max - min);
1165 // if (random->mean * (1 - random->mean) < random->std * random->std)
1166 // THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
1167 // random->mean, random->std);
1170 // ("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
1171 // random_id, random->min, random->max, random->mean, random->std,
1172 // (int)random->generator, random->seed, random_radical);
1174 // if (!random_value)
1175 // random_value = xbt_dict_new_homogeneous(free);
1177 // if (!strcmp(random_radical, "")) {
1178 // res = random_generate(random);
1179 // rd_value = bprintf("%f", res);
1180 // xbt_dict_set(random_value, random_id, rd_value, NULL);
1182 // radical_elements = xbt_str_split(random_radical, ",");
1183 // xbt_dynar_foreach(radical_elements, iter, groups) {
1184 // radical_ends = xbt_str_split(groups, "-");
1185 // switch (xbt_dynar_length(radical_ends)) {
1187 // xbt_assert(!xbt_dict_get_or_null(random_value, random_id),
1188 // "Custom Random '%s' already exists !", random_id);
1189 // res = random_generate(random);
1191 // bprintf("%s%d", random_id,
1192 // atoi(xbt_dynar_getfirst_as(radical_ends, char *)));
1193 // xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL);
1194 // xbt_free(tmpbuf);
1198 // start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
1199 // end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
1200 // for (i = start; i <= end; i++) {
1201 // xbt_assert(!xbt_dict_get_or_null(random_value, random_id),
1202 // "Custom Random '%s' already exists !", bprintf("%s%d",
1205 // res = random_generate(random);
1206 // tmpbuf = bprintf("%s%d", random_id, i);
1207 // xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL);
1208 // xbt_free(tmpbuf);
1212 // XBT_CRITICAL("Malformed radical");
1215 // res = random_generate(random);
1216 // rd_name = bprintf("%s_router", random_id);
1217 // rd_value = bprintf("%f", res);
1218 // xbt_dict_set(random_value, rd_name, rd_value, NULL);
1220 // xbt_dynar_free(&radical_ends);
1223 // xbt_dynar_free(&radical_elements);
1227 static void check_disk_attachment()
1229 xbt_lib_cursor_t cursor;
1232 simgrid::surf::RoutingEdge *host_elm;
1233 xbt_lib_foreach(storage_lib, cursor, key, data) {
1234 if(xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL) != NULL) {
1235 simgrid::surf::Storage *storage = static_cast<simgrid::surf::Storage*>(xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL));
1236 host_elm = sg_routing_edge_by_name_or_null(storage->p_attach);
1238 surf_parse_error("Unable to attach storage %s: host %s doesn't exist.", storage->getName(), storage->p_attach);
1243 void routing_register_callbacks()
1245 sg_platf_postparse_add_cb(routing_parse_postparse);
1246 sg_platf_postparse_add_cb(check_disk_attachment);
1248 instr_routing_define_callbacks();
1252 * \brief Recursive function for finalize
1254 * \param rc the source host name
1256 * This fuction is call by "finalize". It allow to finalize the
1257 * AS or routing components. It delete all the structures.
1259 static void finalize_rec(simgrid::surf::As *as) {
1260 xbt_dict_cursor_t cursor = NULL;
1264 xbt_dict_foreach(as->p_routingSons, cursor, key, elem) {
1271 /** \brief Frees all memory allocated by the routing module */
1272 void routing_exit(void) {
1273 delete routing_platf;
1279 RoutingPlatf::~RoutingPlatf()
1281 xbt_dynar_free(&p_lastRoute);
1282 finalize_rec(p_root);
1288 AS_t surf_AS_get_routing_root() {
1289 return routing_platf->p_root;
1292 const char *surf_AS_get_name(simgrid::surf::As *as) {
1296 static simgrid::surf::As *surf_AS_recursive_get_by_name(
1297 simgrid::surf::As *current, const char * name)
1299 xbt_dict_cursor_t cursor = NULL;
1302 simgrid::surf::As *tmp = NULL;
1304 if(!strcmp(current->p_name, name))
1307 xbt_dict_foreach(current->p_routingSons, cursor, key, elem) {
1308 tmp = surf_AS_recursive_get_by_name(elem, name);
1316 simgrid::surf::As *surf_AS_get_by_name(const char * name)
1318 simgrid::surf::As *as = surf_AS_recursive_get_by_name(routing_platf->p_root, name);
1320 XBT_WARN("Impossible to find an AS with name %s, please check your input", name);
1324 xbt_dict_t surf_AS_get_routing_sons(simgrid::surf::As *as)
1326 return as->p_routingSons;
1329 const char *surf_AS_get_model(simgrid::surf::As *as)
1331 return as->p_modelDesc->name;
1334 xbt_dynar_t surf_AS_get_hosts(simgrid::surf::As *as)
1336 xbt_dynar_t elms = as->p_indexNetworkElm;
1337 sg_routing_edge_t relm;
1340 int count = xbt_dynar_length(elms);
1341 xbt_dynar_t res = xbt_dynar_new(sizeof(xbt_dictelm_t), NULL);
1342 for (index = 0; index < count; index++) {
1343 relm = xbt_dynar_get_as(elms, index, simgrid::surf::RoutingEdge*);
1344 delm = xbt_lib_get_elm_or_null(host_lib, relm->getName());
1346 xbt_dynar_push(res, &delm);
1352 void surf_AS_get_graph(AS_t as, xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) {
1353 as->getGraph(graph, nodes, edges);