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/kernel/routing/NetCard.hpp"
8 #include "src/surf/network_interface.hpp"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
12 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
13 * Note that a router is created, easing the interconnexion with the rest of the world. */
18 AsCluster::AsCluster(As* father, const char* name) : AsImpl(father, name)
22 void AsCluster::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_t route, double* lat)
24 XBT_VERB("cluster getLocalRoute from '%s'[%d] to '%s'[%d]", src->name().c_str(), src->id(), dst->name().c_str(),
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 s_surf_parsing_link_up_down_t 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 s_surf_parsing_link_up_down_t info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
41 route->link_list->push_back(info.linkUp);
44 s_surf_parsing_link_up_down_t info =
45 privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
46 if (info.linkUp) { // link up
47 route->link_list->push_back(info.linkUp);
49 *lat += info.linkUp->latency();
55 route->link_list->push_back(backbone_);
57 *lat += backbone_->latency();
60 if (! dst->isRouter()) { // No specific link for router
61 s_surf_parsing_link_up_down_t info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
63 if (info.linkDown) { // link down
64 route->link_list->push_back(info.linkDown);
66 *lat += info.linkDown->latency();
68 if (hasLimiter_){ // limiter for receiver
69 info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
70 route->link_list->push_back(info.linkUp);
75 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
77 xbt_node_t current, previous, backboneNode = nullptr;
78 s_surf_parsing_link_up_down_t info;
80 xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
82 /* create the router */
83 xbt_node_t routerNode = new_xbt_graph_node(graph, router_->name().c_str(), nodes);
86 const char *link_nameR = backbone_->getName();
87 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
89 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
92 for (auto src: vertices_){
93 if (! src->isRouter()) {
94 previous = new_xbt_graph_node(graph, src->name().c_str(), nodes);
96 info = privateLinks_.at(src->id());
98 if (info.linkUp) { // link up
99 const char *link_name = static_cast<simgrid::surf::Resource*>(info.linkUp)->getName();
100 current = new_xbt_graph_node(graph, link_name, nodes);
101 new_xbt_graph_edge(graph, previous, current, edges);
104 new_xbt_graph_edge(graph, current, backboneNode, edges);
106 new_xbt_graph_edge(graph, current, routerNode, edges);
110 if (info.linkDown) { // link down
111 const char *link_name = static_cast<simgrid::surf::Resource*>(
112 info.linkDown)->getName();
113 current = new_xbt_graph_node(graph, link_name, nodes);
114 new_xbt_graph_edge(graph, previous, current, edges);
117 new_xbt_graph_edge(graph, current, backboneNode, edges);
119 new_xbt_graph_edge(graph, current, routerNode, edges);
126 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
127 s_surf_parsing_link_up_down_t info;
128 char* link_id = bprintf("%s_link_%d", cluster->id, id);
130 s_sg_platf_link_cbarg_t link;
131 memset(&link, 0, sizeof(link));
133 link.bandwidth = cluster->bw;
134 link.latency = cluster->lat;
135 link.policy = cluster->sharing_policy;
136 sg_platf_new_link(&link);
138 if (link.policy == SURF_LINK_FULLDUPLEX) {
139 char *tmp_link = bprintf("%s_UP", link_id);
140 info.linkUp = Link::byName(tmp_link);
142 tmp_link = bprintf("%s_DOWN", link_id);
143 info.linkDown = Link::byName(tmp_link);
146 info.linkUp = Link::byName(link_id);
147 info.linkDown = info.linkUp;
149 privateLinks_.insert({position, info});