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"
11 #include "simgrid/platf_interface.h" // platform creation API internal interface
12 #include "simgrid/sg_config.h"
13 #include "storage_interface.hpp"
14 #include "src/surf/platform.hpp"
15 #include "surf/surfxml_parse_values.h"
17 #include "src/surf/surf_routing_cluster_torus.hpp"
18 #include "src/surf/surf_routing_cluster_fat_tree.hpp"
19 #include "src/surf/surf_routing_dijkstra.hpp"
20 #include "src/surf/surf_routing_floyd.hpp"
21 #include "src/surf/surf_routing_full.hpp"
22 #include "src/surf/surf_routing_vivaldi.hpp"
29 simgrid::xbt::signal<void(simgrid::surf::NetCard*)> netcardCreatedCallbacks;
30 simgrid::xbt::signal<void(simgrid::surf::As*)> asCreatedCallbacks;
32 As::As(const char*name)
33 : p_name(xbt_strdup(name))
37 xbt_dict_free(&p_routingSons);
38 xbt_dynar_free(&p_indexNetworkElm);
39 xbt_dynar_free(&p_linkUpDownList);
45 }} // namespace simgrid::surf
48 * @ingroup SURF_build_api
49 * @brief A library containing all known hosts
53 int COORD_HOST_LEVEL=0; //Coordinates level
55 int MSG_FILE_LEVEL; //Msg file level
57 int SIMIX_STORAGE_LEVEL; //Simix storage level
58 int MSG_STORAGE_LEVEL; //Msg storage level
60 xbt_lib_t as_router_lib;
61 int ROUTING_ASR_LEVEL; //Routing level
62 int COORD_ASR_LEVEL; //Coordinates level
63 int NS3_ASR_LEVEL; //host node for ns3
64 int ROUTING_PROP_ASR_LEVEL; //Where the properties are stored
66 /** @brief Retrieve a netcard from its name
68 * Netcards are the thing that connect host or routers to the network
70 simgrid::surf::NetCard *sg_netcard_by_name_or_null(const char *name)
72 sg_host_t h = sg_host_by_name(name);
73 simgrid::surf::NetCard *net_elm = h==NULL?NULL: h->pimpl_netcard;
75 net_elm = (simgrid::surf::NetCard*) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
80 simgrid::surf::RoutingPlatf *routing_platf = NULL;
82 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
84 /** The current AS in the parsing */
85 static simgrid::surf::As *current_routing = NULL;
86 simgrid::surf::As* routing_get_current()
88 return current_routing;
91 /** @brief Add a link connecting an host to the rest of its AS (which must be cluster or vivaldi) */
92 void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t netcard_arg)
94 simgrid::surf::NetCard *netcard = sg_host_by_name(netcard_arg->id)->pimpl_netcard;
95 xbt_assert(netcard, "Host '%s' not found!", netcard_arg->id);
96 xbt_assert(dynamic_cast<simgrid::surf::AsCluster*>(current_routing) ||
97 dynamic_cast<simgrid::surf::AsVivaldi*>(current_routing),
98 "Only hosts from Cluster and Vivaldi ASes can get a host_link.");
100 s_surf_parsing_link_up_down_t link_up_down;
101 link_up_down.link_up = Link::byName(netcard_arg->link_up);
102 link_up_down.link_down = Link::byName(netcard_arg->link_down);
104 xbt_assert(link_up_down.link_up, "Link '%s' not found!",netcard_arg->link_up);
105 xbt_assert(link_up_down.link_down, "Link '%s' not found!",netcard_arg->link_down);
107 // If dynar is is greater than netcard id and if the host_link is already defined
108 if((int)xbt_dynar_length(current_routing->p_linkUpDownList) > netcard->getId() &&
109 xbt_dynar_get_as(current_routing->p_linkUpDownList, netcard->getId(), void*))
110 surf_parse_error("Host_link for '%s' is already defined!",netcard_arg->id);
112 XBT_DEBUG("Push Host_link for host '%s' to position %d", netcard->getName(), netcard->getId());
113 xbt_dynar_set_as(current_routing->p_linkUpDownList, netcard->getId(), s_surf_parsing_link_up_down_t, link_up_down);
116 void sg_platf_new_trace(sg_platf_trace_cbarg_t trace)
118 tmgr_trace_t tmgr_trace;
119 if (!trace->file || strcmp(trace->file, "") != 0) {
120 tmgr_trace = tmgr_trace_new_from_file(trace->file);
122 xbt_assert(strcmp(trace->pc_data, ""),
123 "Trace '%s' must have either a content, or point to a file on disk.",trace->id);
124 tmgr_trace = tmgr_trace_new_from_string(trace->id, trace->pc_data, trace->periodicity);
126 xbt_dict_set(traces_set_list, trace->id, (void *) tmgr_trace, NULL);
130 * \brief Make a new routing component to the platform
132 * Add a new autonomous system to the platform. Any elements (such as host,
133 * router or sub-AS) added after this call and before the corresponding call
134 * to sg_platf_new_AS_close() will be added to this AS.
136 * Once this function was called, the configuration concerning the used
137 * models cannot be changed anymore.
139 * @param AS_id name of this autonomous system. Must be unique in the platform
140 * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
142 void routing_AS_begin(sg_platf_AS_cbarg_t AS)
144 XBT_DEBUG("routing_AS_begin");
146 xbt_assert(NULL == xbt_lib_get_or_null(as_router_lib, AS->id, ROUTING_ASR_LEVEL),
147 "Refusing to create a second AS called \"%s\".", AS->id);
149 _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent
150 * any further config now that we created some real content */
153 /* search the routing model */
154 simgrid::surf::As *new_as = NULL;
156 case A_surfxml_AS_routing_Cluster: new_as = new simgrid::surf::AsCluster(AS->id); break;
157 case A_surfxml_AS_routing_ClusterTorus: new_as = new simgrid::surf::AsClusterTorus(AS->id); break;
158 case A_surfxml_AS_routing_ClusterFatTree: new_as = new simgrid::surf::AsClusterFatTree(AS->id); break;
159 case A_surfxml_AS_routing_Dijkstra: new_as = new simgrid::surf::AsDijkstra(AS->id, 0); break;
160 case A_surfxml_AS_routing_DijkstraCache: new_as = new simgrid::surf::AsDijkstra(AS->id, 1); break;
161 case A_surfxml_AS_routing_Floyd: new_as = new simgrid::surf::AsFloyd(AS->id); break;
162 case A_surfxml_AS_routing_Full: new_as = new simgrid::surf::AsFull(AS->id); break;
163 case A_surfxml_AS_routing_None: new_as = new simgrid::surf::AsNone(AS->id); break;
164 case A_surfxml_AS_routing_Vivaldi: new_as = new simgrid::surf::AsVivaldi(AS->id); break;
165 default: xbt_die("Not a valid model!"); break;
168 /* make a new routing component */
169 simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(new_as->p_name, SURF_NETWORK_ELEMENT_AS, current_routing);
171 if (current_routing == NULL && routing_platf->p_root == NULL) {
172 /* it is the first one */
173 new_as->p_routingFather = NULL;
174 routing_platf->p_root = new_as;
176 } else if (current_routing != NULL && routing_platf->p_root != NULL) {
178 xbt_assert(!xbt_dict_get_or_null(current_routing->p_routingSons, AS->id),
179 "The AS \"%s\" already exists", AS->id);
180 /* it is a part of the tree */
181 new_as->p_routingFather = current_routing;
182 /* set the father behavior */
183 if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
184 current_routing->p_hierarchy = SURF_ROUTING_RECURSIVE;
185 /* add to the sons dictionary */
186 xbt_dict_set(current_routing->p_routingSons, AS->id,
187 (void *) new_as, NULL);
188 /* add to the father element list */
189 netcard->setId(current_routing->parseAS(netcard));
191 THROWF(arg_error, 0, "All defined components must belong to a AS");
194 xbt_lib_set(as_router_lib, netcard->getName(), ROUTING_ASR_LEVEL,
196 XBT_DEBUG("Having set name '%s' id '%d'", new_as->p_name, netcard->getId());
198 /* set the new current component of the tree */
199 current_routing = new_as;
200 current_routing->p_netcard = netcard;
202 simgrid::surf::netcardCreatedCallbacks(netcard);
203 simgrid::surf::asCreatedCallbacks(new_as);
207 * \brief Specify that the current description of AS is finished
209 * Once you've declared all the content of your AS, you have to close
210 * it with this call. Your AS is not usable until you call this function.
212 * @fixme: this call is not as robust as wanted: bad things WILL happen
213 * if you call it twice for the same AS, or if you forget calling it, or
214 * even if you add stuff to a closed AS
217 void routing_AS_end()
219 xbt_assert(current_routing, "Cannot seal the current AS: none under construction");
220 current_routing->Seal();
221 current_routing = current_routing->p_routingFather;
224 /* Aux Business methods */
227 * \brief Get the AS father and the first elements of the chain
229 * \param src the source host name
230 * \param dst the destination host name
232 * Get the common father of the to processing units, and the first different
233 * father in the chain
235 static void elements_father(sg_netcard_t src, sg_netcard_t dst,
240 xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
241 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
242 simgrid::surf::As *src_as, *dst_as;
243 simgrid::surf::As *path_src[ELEMENTS_FATHER_MAXDEPTH];
244 simgrid::surf::As *path_dst[ELEMENTS_FATHER_MAXDEPTH];
247 simgrid::surf::As *current;
248 simgrid::surf::As *current_src;
249 simgrid::surf::As *current_dst;
250 simgrid::surf::As *father;
252 /* (1) find the as where the src and dst are located */
253 sg_netcard_t src_data = src;
254 sg_netcard_t dst_data = dst;
255 src_as = src_data->getRcComponent();
256 dst_as = dst_data->getRcComponent();
258 char* src_name = src_data->getName();
259 char* dst_name = dst_data->getName();
262 xbt_assert(src_as && dst_as,
263 "Ask for route \"from\"(%s) or \"to\"(%s) no found", src_name, dst_name);
265 /* (2) find the path to the root routing component */
266 for (current = src_as; current != NULL; current = current->p_routingFather) {
267 if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
268 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
269 path_src[index_src++] = current;
271 for (current = dst_as; current != NULL; current = current->p_routingFather) {
272 if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
273 xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
274 path_dst[index_dst++] = current;
277 /* (3) find the common father */
279 current_src = path_src[--index_src];
280 current_dst = path_dst[--index_dst];
281 } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
283 /* (4) they are not in the same routing component, make the path */
284 if (current_src == current_dst)
285 father = current_src;
287 father = path_src[index_src + 1];
289 /* (5) result generation */
290 *res_father = father; /* first the common father of src and dst */
291 *res_src = current_src; /* second the first different father of src */
292 *res_dst = current_dst; /* three the first different father of dst */
294 #undef ELEMENTS_FATHER_MAXDEPTH
297 /* Global Business methods */
300 * \brief Recursive function for get_route_latency
302 * \param src the source host name
303 * \param dst the destination host name
304 * \param *route the route where the links are stored. It is either NULL or a ready to use dynar
305 * \param *latency the latency, if needed
307 * This function is called by "get_route" and "get_latency". It allows to walk
308 * recursively through the ASes tree.
310 static void _get_route_and_latency(
311 simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst,
312 xbt_dynar_t * links, double *latency)
314 s_sg_platf_route_cbarg_t route = SG_PLATF_ROUTE_INITIALIZER;
315 memset(&route,0,sizeof(route));
317 xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
318 XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src->getName(), dst->getName());
320 /* Find how src and dst are interconnected */
321 simgrid::surf::As *common_father, *src_father, *dst_father;
322 elements_father(src, dst, &common_father, &src_father, &dst_father);
323 XBT_DEBUG("elements_father: common father '%s' src_father '%s' dst_father '%s'",
324 common_father->p_name, src_father->p_name, dst_father->p_name);
326 /* Check whether a direct bypass is defined */
327 sg_platf_route_cbarg_t e_route_bypass = NULL;
328 //FIXME:REMOVE:if (common_father->get_bypass_route)
330 e_route_bypass = common_father->getBypassRoute(src, dst, latency);
332 /* Common ancestor is kind enough to declare a bypass route from src to dst -- use it and bail out */
333 if (e_route_bypass) {
334 xbt_dynar_merge(links, &e_route_bypass->link_list);
335 routing_route_free(e_route_bypass);
339 /* If src and dst are in the same AS, life is good */
340 if (src_father == dst_father) { /* SURF_ROUTING_BASE */
341 route.link_list = *links;
342 common_father->getRouteAndLatency(src, dst, &route, latency);
343 // if vivaldi latency+=vivaldi(src,dst)
347 /* Not in the same AS, no bypass. We'll have to find our path between the ASes recursively*/
349 route.link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
350 // Find the net_card corresponding to father
351 simgrid::surf::NetCard *src_father_netcard = src_father->p_netcard;
352 simgrid::surf::NetCard *dst_father_netcard = dst_father->p_netcard;
354 common_father->getRouteAndLatency(src_father_netcard, dst_father_netcard,
357 xbt_assert((route.gw_src != NULL) && (route.gw_dst != NULL),
358 "bad gateways for route from \"%s\" to \"%s\"", src->getName(), dst->getName());
360 sg_netcard_t src_gateway_net_elm = route.gw_src;
361 sg_netcard_t dst_gateway_net_elm = route.gw_dst;
363 /* If source gateway is not our source, we have to recursively find our way up to this point */
364 if (src != src_gateway_net_elm)
365 _get_route_and_latency(src, src_gateway_net_elm, links, latency);
366 xbt_dynar_merge(links, &route.link_list);
368 /* If dest gateway is not our destination, we have to recursively find our way from this point */
369 if (dst_gateway_net_elm != dst)
370 _get_route_and_latency(dst_gateway_net_elm, dst, links, latency);
374 AS_t surf_platf_get_root(routing_platf_t platf){
375 return platf->p_root;
378 e_surf_network_element_type_t surf_routing_edge_get_rc_type(sg_netcard_t netcard){
379 return netcard->getRcType();
386 * \brief Find a route between hosts
388 * \param src the network_element_t for src host
389 * \param dst the network_element_t for dst host
390 * \param route where to store the list of links.
391 * If *route=NULL, create a short lived dynar. Else, fill the provided dynar
392 * \param latency where to store the latency experienced on the path (or NULL if not interested)
393 * It is the caller responsability to initialize latency to 0 (we add to provided route)
396 * walk through the routing components tree and find a route between hosts
397 * by calling each "get_route" function in each routing component.
399 void RoutingPlatf::getRouteAndLatency(NetCard *src, NetCard *dst, xbt_dynar_t* route, double *latency)
401 XBT_DEBUG("getRouteAndLatency from %s to %s", src->getName(), dst->getName());
402 if (NULL == *route) {
403 xbt_dynar_reset(routing_platf->p_lastRoute);
404 *route = routing_platf->p_lastRoute;
407 _get_route_and_latency(src, dst, route, latency);
409 xbt_assert(!latency || *latency >= 0.0,
410 "negative latency on route between \"%s\" and \"%s\"", src->getName(), dst->getName());
413 xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
414 return recursiveGetOneLinkRoutes(p_root);
417 xbt_dynar_t RoutingPlatf::recursiveGetOneLinkRoutes(As *rc)
419 xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
421 //adding my one link routes
422 xbt_dynar_t onelink_mine = rc->getOneLinkRoutes();
424 xbt_dynar_merge(&ret,&onelink_mine);
428 xbt_dict_cursor_t cursor = NULL;
430 xbt_dict_foreach(rc->p_routingSons, cursor, key, rc_child) {
431 xbt_dynar_t onelink_child = recursiveGetOneLinkRoutes(rc_child);
433 xbt_dynar_merge(&ret,&onelink_child);
441 e_surf_network_element_type_t routing_get_network_element_type(const char *name)
443 simgrid::surf::NetCard *rc = sg_netcard_by_name_or_null(name);
445 return rc->getRcType();
447 return SURF_NETWORK_ELEMENT_NULL;
450 /** @brief create the root AS */
451 void routing_model_create( void *loopback)
453 routing_platf = new simgrid::surf::RoutingPlatf(loopback);
456 /* ************************************************************************** */
457 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
459 void routing_cluster_add_backbone(void* bb) {
460 simgrid::surf::AsCluster *cluster = dynamic_cast<simgrid::surf::AsCluster*>(current_routing);
462 xbt_assert(cluster, "Only hosts from Cluster can get a backbone.");
463 xbt_assert(nullptr == cluster->p_backbone, "Cluster %s already has a backbone link!", cluster->p_name);
465 cluster->p_backbone = static_cast<simgrid::surf::Link*>(bb);
466 XBT_DEBUG("Add a backbone to AS '%s'", current_routing->p_name);
469 void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
472 char *groups , *host_id , *link_id = NULL;
474 xbt_dynar_t radical_elements;
475 xbt_dynar_t radical_ends;
478 radical_elements = xbt_str_split(cabinet->radical, ",");
479 xbt_dynar_foreach(radical_elements, iter, groups) {
481 radical_ends = xbt_str_split(groups, "-");
482 start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
484 switch (xbt_dynar_length(radical_ends)) {
489 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
492 surf_parse_error("Malformed radical");
495 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
496 memset(&host, 0, sizeof(host));
497 host.initiallyOn = 1;
499 host.speed_scale = 1.0;
500 host.core_amount = 1;
502 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
503 memset(&link, 0, sizeof(link));
504 link.initiallyOn = 1;
505 link.policy = SURF_LINK_FULLDUPLEX;
506 link.latency = cabinet->lat;
507 link.bandwidth = cabinet->bw;
509 s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
510 memset(&host_link, 0, sizeof(host_link));
512 for (i = start; i <= end; i++) {
513 host_id = bprintf("%s%d%s",cabinet->prefix,i,cabinet->suffix);
514 link_id = bprintf("link_%s%d%s",cabinet->prefix,i,cabinet->suffix);
517 host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
518 xbt_dynar_push(host.speed_peak,&cabinet->speed);
519 sg_platf_new_host(&host);
520 xbt_dynar_free(&host.speed_peak);
521 sg_platf_new_link(&link);
523 char* link_up = bprintf("%s_UP",link_id);
524 char* link_down = bprintf("%s_DOWN",link_id);
525 host_link.id = host_id;
526 host_link.link_up = link_up;
527 host_link.link_down = link_down;
528 sg_platf_new_hostlink(&host_link);
536 xbt_dynar_free(&radical_ends);
538 xbt_dynar_free(&radical_elements);
541 void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
543 using simgrid::surf::NetCard;
544 using simgrid::surf::AsCluster;
546 char *host_id = NULL;
547 char *link_id = NULL;
548 char *router_id = NULL;
551 host_id = HOST_PEER(peer->id);
552 link_id = LINK_PEER(peer->id);
553 router_id = ROUTER_PEER(peer->id);
555 XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", peer->id);
556 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
558 AS.routing = A_surfxml_AS_routing_Cluster;
559 sg_platf_new_AS_begin(&AS);
561 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->speed);
562 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
563 memset(&host, 0, sizeof(host));
564 host.initiallyOn = 1;
567 host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
568 xbt_dynar_push(host.speed_peak,&peer->speed);
570 //host.power_peak = peer->power;
571 host.speed_scale = 1.0;
572 host.speed_trace = peer->availability_trace;
573 host.state_trace = peer->state_trace;
574 host.core_amount = 1;
575 sg_platf_new_host(&host);
576 xbt_dynar_free(&host.speed_peak);
578 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
579 memset(&link, 0, sizeof(link));
580 link.initiallyOn = 1;
581 link.policy = SURF_LINK_SHARED;
582 link.latency = peer->lat;
584 char* link_up = bprintf("%s_UP",link_id);
585 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_up,
586 peer->bw_out, peer->lat);
588 link.bandwidth = peer->bw_out;
589 sg_platf_new_link(&link);
591 char* link_down = bprintf("%s_DOWN",link_id);
592 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_down,
593 peer->bw_in, peer->lat);
595 link.bandwidth = peer->bw_in;
596 sg_platf_new_link(&link);
598 XBT_DEBUG("<host_link\tid=\"%s\"\tup=\"%s\"\tdown=\"%s\" />", host_id,link_up,link_down);
599 s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
600 memset(&host_link, 0, sizeof(host_link));
601 host_link.id = host_id;
602 host_link.link_up = link_up;
603 host_link.link_down = link_down;
604 sg_platf_new_hostlink(&host_link);
606 XBT_DEBUG("<router id=\"%s\"/>", router_id);
607 s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
608 memset(&router, 0, sizeof(router));
609 router.id = router_id;
610 router.coord = peer->coord;
611 sg_platf_new_router(&router);
612 static_cast<AsCluster*>(current_routing)->p_router = static_cast<NetCard*>(xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL));
615 sg_platf_new_AS_end();
618 //xbt_dynar_free(&tab_elements_num);
626 // static void routing_parse_Srandom(void)
628 // double mean, std, min, max, seed;
629 // char *random_id = A_surfxml_random_id;
630 // char *random_radical = A_surfxml_random_radical;
631 // char *rd_name = NULL;
633 // mean = surf_parse_get_double(A_surfxml_random_mean);
634 // std = surf_parse_get_double(A_surfxml_random_std___deviation);
635 // min = surf_parse_get_double(A_surfxml_random_min);
636 // max = surf_parse_get_double(A_surfxml_random_max);
637 // seed = surf_parse_get_double(A_surfxml_random_seed);
641 // random_data_t random = xbt_new0(s_random_data_t, 1);
644 // xbt_dynar_t radical_elements;
645 // unsigned int iter;
648 // xbt_dynar_t radical_ends;
650 // switch (A_surfxml_random_generator) {
651 // case AU_surfxml_random_generator:
652 // case A_surfxml_random_generator_NONE:
653 // random->generator = NONE;
655 // case A_surfxml_random_generator_DRAND48:
656 // random->generator = DRAND48;
658 // case A_surfxml_random_generator_RAND:
659 // random->generator = RAND;
661 // case A_surfxml_random_generator_RNGSTREAM:
662 // random->generator = RNGSTREAM;
665 // surf_parse_error("Invalid random generator");
668 // random->seed = seed;
669 // random->min = min;
670 // random->max = max;
672 // /* Check user stupidities */
674 // THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
676 // THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean, min);
678 // THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean, max);
680 // /* normalize the mean and standard deviation before storing */
681 // random->mean = (mean - min) / (max - min);
682 // random->std = std / (max - min);
684 // if (random->mean * (1 - random->mean) < random->std * random->std)
685 // THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
686 // random->mean, random->std);
689 // ("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
690 // random_id, random->min, random->max, random->mean, random->std,
691 // (int)random->generator, random->seed, random_radical);
693 // if (!random_value)
694 // random_value = xbt_dict_new_homogeneous(free);
696 // if (!strcmp(random_radical, "")) {
697 // res = random_generate(random);
698 // rd_value = bprintf("%f", res);
699 // xbt_dict_set(random_value, random_id, rd_value, NULL);
701 // radical_elements = xbt_str_split(random_radical, ",");
702 // xbt_dynar_foreach(radical_elements, iter, groups) {
703 // radical_ends = xbt_str_split(groups, "-");
704 // switch (xbt_dynar_length(radical_ends)) {
706 // xbt_assert(!xbt_dict_get_or_null(random_value, random_id),
707 // "Custom Random '%s' already exists !", random_id);
708 // res = random_generate(random);
710 // bprintf("%s%d", random_id,
711 // atoi(xbt_dynar_getfirst_as(radical_ends, char *)));
712 // xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL);
717 // start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
718 // end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
719 // for (i = start; i <= end; i++) {
720 // xbt_assert(!xbt_dict_get_or_null(random_value, random_id),
721 // "Custom Random '%s' already exists !", bprintf("%s%d",
724 // res = random_generate(random);
725 // tmpbuf = bprintf("%s%d", random_id, i);
726 // xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL);
731 // XBT_CRITICAL("Malformed radical");
734 // res = random_generate(random);
735 // rd_name = bprintf("%s_router", random_id);
736 // rd_value = bprintf("%f", res);
737 // xbt_dict_set(random_value, rd_name, rd_value, NULL);
739 // xbt_dynar_free(&radical_ends);
742 // xbt_dynar_free(&radical_elements);
746 static void check_disk_attachment()
748 xbt_lib_cursor_t cursor;
751 simgrid::surf::NetCard *host_elm;
752 xbt_lib_foreach(storage_lib, cursor, key, data) {
753 if(xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL) != NULL) {
754 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));
755 host_elm = sg_netcard_by_name_or_null(storage->p_attach);
757 surf_parse_error("Unable to attach storage %s: host %s doesn't exist.", storage->getName(), storage->p_attach);
762 void routing_register_callbacks()
764 simgrid::surf::on_postparse.connect(check_disk_attachment);
766 instr_routing_define_callbacks();
770 * \brief Recursive function for finalize
772 * \param rc the source host name
774 * This fuction is call by "finalize". It allow to finalize the
775 * AS or routing components. It delete all the structures.
777 static void finalize_rec(simgrid::surf::As *as) {
778 xbt_dict_cursor_t cursor = NULL;
782 xbt_dict_foreach(as->p_routingSons, cursor, key, elem) {
789 /** \brief Frees all memory allocated by the routing module */
790 void routing_exit(void) {
791 delete routing_platf;
797 RoutingPlatf::RoutingPlatf(void *loopback)
798 : p_loopback(loopback)
801 RoutingPlatf::~RoutingPlatf()
803 xbt_dynar_free(&p_lastRoute);
804 finalize_rec(p_root);
810 AS_t surf_AS_get_routing_root() {
811 return routing_platf->p_root;
814 const char *surf_AS_get_name(simgrid::surf::As *as) {
818 static simgrid::surf::As *surf_AS_recursive_get_by_name(
819 simgrid::surf::As *current, const char * name)
821 xbt_dict_cursor_t cursor = NULL;
824 simgrid::surf::As *tmp = NULL;
826 if(!strcmp(current->p_name, name))
829 xbt_dict_foreach(current->p_routingSons, cursor, key, elem) {
830 tmp = surf_AS_recursive_get_by_name(elem, name);
838 simgrid::surf::As *surf_AS_get_by_name(const char * name)
840 simgrid::surf::As *as = surf_AS_recursive_get_by_name(routing_platf->p_root, name);
842 XBT_WARN("Impossible to find an AS with name %s, please check your input", name);
846 xbt_dict_t surf_AS_get_routing_sons(simgrid::surf::As *as)
848 return as->p_routingSons;
851 xbt_dynar_t surf_AS_get_hosts(simgrid::surf::As *as)
853 xbt_dynar_t elms = as->p_indexNetworkElm;
854 int count = xbt_dynar_length(elms);
855 xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), NULL);
856 for (int index = 0; index < count; index++) {
858 xbt_dynar_get_as(elms, index, simgrid::surf::NetCard*);
859 sg_host_t delm = simgrid::s4u::Host::by_name_or_null(relm->getName());
861 xbt_dynar_push(res, &delm);
867 void surf_AS_get_graph(AS_t as, xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) {
868 as->getGraph(graph, nodes, edges);