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/kernel/routing/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(As* father, const char* name) : AsImpl(father, 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]", src->name().c_str(), src->id(),
25 dst->name().c_str(), dst->id());
26 xbt_assert(!privateLinks_.empty(),
27 "Cluster routing: no links attached to the source node - did you use host_link tag?");
29 if (! src->isRouter()) { // No specific link for router
31 if((src->id() == dst->id()) && hasLoopback_ ){
32 info = privateLinks_.at(src->id() * linkCountPerNode_);
33 route->link_list->push_back(info.linkUp);
35 *lat += info.linkUp->latency();
39 if (hasLimiter_){ // limiter for sender
40 info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_?1:0));
41 route->link_list->push_back(info.linkUp);
44 info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_?1:0) + (hasLimiter_?1:0));
45 if (info.linkUp) { // link up
46 route->link_list->push_back(info.linkUp);
48 *lat += info.linkUp->latency();
54 route->link_list->push_back(backbone_);
56 *lat += backbone_->latency();
59 if (! dst->isRouter()) { // No specific link for router
60 info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
62 if (info.linkDown) { // link down
63 route->link_list->push_back(info.linkDown);
65 *lat += info.linkDown->latency();
67 if (hasLimiter_){ // limiter for receiver
68 info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
69 route->link_list->push_back(info.linkUp);
74 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
76 xbt_node_t current, previous, backboneNode = nullptr;
77 s_surf_parsing_link_up_down_t info;
79 xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
81 /* create the router */
82 xbt_node_t routerNode = new_xbt_graph_node(graph, router_->name().c_str(), nodes);
85 const char *link_nameR = backbone_->getName();
86 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
88 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
91 for (auto src: vertices_){
92 if (! src->isRouter()) {
93 previous = new_xbt_graph_node(graph, src->name().c_str(), nodes);
95 info = privateLinks_.at(src->id());
97 if (info.linkUp) { // link up
98 const char *link_name = static_cast<simgrid::surf::Resource*>(info.linkUp)->getName();
99 current = new_xbt_graph_node(graph, link_name, nodes);
100 new_xbt_graph_edge(graph, previous, current, edges);
103 new_xbt_graph_edge(graph, current, backboneNode, edges);
105 new_xbt_graph_edge(graph, current, routerNode, edges);
109 if (info.linkDown) { // link down
110 const char *link_name = static_cast<simgrid::surf::Resource*>(
111 info.linkDown)->getName();
112 current = new_xbt_graph_node(graph, link_name, nodes);
113 new_xbt_graph_edge(graph, previous, current, edges);
116 new_xbt_graph_edge(graph, current, backboneNode, edges);
118 new_xbt_graph_edge(graph, current, routerNode, edges);
125 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
126 s_surf_parsing_link_up_down_t info;
127 char* link_id = bprintf("%s_link_%d", cluster->id, id);
129 s_sg_platf_link_cbarg_t link;
130 memset(&link, 0, sizeof(link));
132 link.bandwidth = cluster->bw;
133 link.latency = cluster->lat;
134 link.policy = cluster->sharing_policy;
135 sg_platf_new_link(&link);
137 if (link.policy == SURF_LINK_FULLDUPLEX) {
138 char *tmp_link = bprintf("%s_UP", link_id);
139 info.linkUp = Link::byName(tmp_link);
141 tmp_link = bprintf("%s_DOWN", link_id);
142 info.linkDown = Link::byName(tmp_link);
145 info.linkUp = Link::byName(link_id);
146 info.linkDown = info.linkUp;
148 privateLinks_.insert({position, info});