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_cluster.hpp"
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
11 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
12 * Note that a router is created, easing the interconnexion with the rest of the world.
17 AsCluster::AsCluster(const char*name)
21 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
23 s_surf_parsing_link_up_down_t info;
24 XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
25 src->name(), src->id(), dst->name(), dst->id());
27 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
29 if((src->id() == dst->id()) && has_loopback_ ){
30 info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_, s_surf_parsing_link_up_down_t);
31 xbt_dynar_push_as(route->link_list, void *, info.link_up);
33 *lat += static_cast<Link*>(info.link_up)->getLatency();
38 if (has_limiter_){ // limiter for sender
39 info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
40 xbt_dynar_push_as(route->link_list, void *, info.link_up);
43 info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
44 if (info.link_up) { // link up
45 xbt_dynar_push_as(route->link_list, void *, info.link_up);
47 *lat += static_cast<Link*>(info.link_up)->getLatency();
53 xbt_dynar_push_as(route->link_list, void *,
54 static_cast<simgrid::surf::Resource*>(backbone_));
56 *lat += backbone_->getLatency();
59 if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
60 info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
62 if (info.link_down) { // link down
63 xbt_dynar_push_as(route->link_list, void *, info.link_down);
65 *lat += static_cast<Link*>(info.link_down)->getLatency();
67 if (has_limiter_){ // limiter for receiver
68 info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
69 xbt_dynar_push_as(route->link_list, void *, info.link_up);
74 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
77 int table_size = xbt_dynar_length(vertices_);
80 xbt_node_t current, previous, backboneNode = NULL, routerNode;
81 s_surf_parsing_link_up_down_t info;
83 xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
85 /* create the router */
86 char *link_name = router_->name();
87 routerNode = new_xbt_graph_node(graph, link_name, nodes);
90 const char *link_nameR = backbone_->getName();
91 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
93 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
96 for (isrc = 0; isrc < table_size; isrc++) {
97 src = xbt_dynar_get_as(vertices_, isrc, NetCard*);
99 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
100 previous = new_xbt_graph_node(graph, src->name(), nodes);
102 info = xbt_dynar_get_as(upDownLinks, src->id(), s_surf_parsing_link_up_down_t);
104 if (info.link_up) { // link up
106 const char *link_name = static_cast<simgrid::surf::Resource*>(
107 info.link_up)->getName();
108 current = new_xbt_graph_node(graph, link_name, nodes);
109 new_xbt_graph_edge(graph, previous, current, edges);
112 new_xbt_graph_edge(graph, current, backboneNode, edges);
114 new_xbt_graph_edge(graph, current, routerNode, edges);
119 if (info.link_down) { // link down
120 const char *link_name = static_cast<simgrid::surf::Resource*>(
121 info.link_down)->getName();
122 current = new_xbt_graph_node(graph, link_name, nodes);
123 new_xbt_graph_edge(graph, previous, current, edges);
126 new_xbt_graph_edge(graph, current, backboneNode, edges);
128 new_xbt_graph_edge(graph, current, routerNode, edges);
136 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
137 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
138 s_surf_parsing_link_up_down_t info;
139 char* link_id = bprintf("%s_link_%d", cluster->id, id);
141 memset(&link, 0, sizeof(link));
143 link.bandwidth = cluster->bw;
144 link.latency = cluster->lat;
145 link.policy = cluster->sharing_policy;
146 sg_platf_new_link(&link);
148 if (link.policy == SURF_LINK_FULLDUPLEX) {
149 char *tmp_link = bprintf("%s_UP", link_id);
150 info.link_up = sg_link_by_name(tmp_link);
152 tmp_link = bprintf("%s_DOWN", link_id);
153 info.link_down = sg_link_by_name(tmp_link);
156 info.link_up = sg_link_by_name(link_id);
157 info.link_down = info.link_up;
159 xbt_dynar_set(upDownLinks, position, &info);