1 /* Copyright (c) 2009-2016. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/surf/AsCluster.hpp"
7 #include "src/surf/network_interface.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->isRouter()) { // 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 route->link_list->push_back(info.link_up);
33 *lat += 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 route->link_list->push_back((Link*)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 route->link_list->push_back(info.link_up);
47 *lat += info.link_up->getLatency();
53 route->link_list->push_back(backbone_);
55 *lat += backbone_->getLatency();
58 if (! dst->isRouter()) { // No specific link for router
59 info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
61 if (info.link_down) { // link down
62 route->link_list->push_back(info.link_down);
64 *lat += info.link_down->getLatency();
66 if (has_limiter_){ // limiter for receiver
67 info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
68 route->link_list->push_back(info.link_up);
73 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
76 int table_size = xbt_dynar_length(vertices_);
79 xbt_node_t current, previous, backboneNode = NULL, routerNode;
80 s_surf_parsing_link_up_down_t info;
82 xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
84 /* create the router */
85 char *link_name = router_->name();
86 routerNode = new_xbt_graph_node(graph, link_name, nodes);
89 const char *link_nameR = backbone_->getName();
90 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
92 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
95 for (isrc = 0; isrc < table_size; isrc++) {
96 src = xbt_dynar_get_as(vertices_, isrc, NetCard*);
98 if (! src->isRouter()) {
99 previous = new_xbt_graph_node(graph, src->name(), nodes);
101 info = xbt_dynar_get_as(upDownLinks, src->id(), s_surf_parsing_link_up_down_t);
103 if (info.link_up) { // link up
105 const char *link_name = static_cast<simgrid::surf::Resource*>(
106 info.link_up)->getName();
107 current = new_xbt_graph_node(graph, link_name, nodes);
108 new_xbt_graph_edge(graph, previous, current, edges);
111 new_xbt_graph_edge(graph, current, backboneNode, edges);
113 new_xbt_graph_edge(graph, current, routerNode, edges);
118 if (info.link_down) { // link down
119 const char *link_name = static_cast<simgrid::surf::Resource*>(
120 info.link_down)->getName();
121 current = new_xbt_graph_node(graph, link_name, nodes);
122 new_xbt_graph_edge(graph, previous, current, edges);
125 new_xbt_graph_edge(graph, current, backboneNode, edges);
127 new_xbt_graph_edge(graph, current, routerNode, edges);
135 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
136 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
137 s_surf_parsing_link_up_down_t info;
138 char* link_id = bprintf("%s_link_%d", cluster->id, id);
140 memset(&link, 0, sizeof(link));
142 link.bandwidth = cluster->bw;
143 link.latency = cluster->lat;
144 link.policy = cluster->sharing_policy;
145 sg_platf_new_link(&link);
147 if (link.policy == SURF_LINK_FULLDUPLEX) {
148 char *tmp_link = bprintf("%s_UP", link_id);
149 info.link_up = sg_link_by_name(tmp_link);
151 tmp_link = bprintf("%s_DOWN", link_id);
152 info.link_down = sg_link_by_name(tmp_link);
155 info.link_up = sg_link_by_name(link_id);
156 info.link_down = info.link_up;
158 xbt_dynar_set(upDownLinks, position, &info);