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/ClusterZone.hpp"
7 #include "src/kernel/routing/NetPoint.hpp"
8 #include "src/kernel/routing/RoutedZone.hpp"
9 #include "src/surf/network_interface.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
13 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
14 * Note that a router is created, easing the interconnexion with the rest of the world. */
19 ClusterZone::ClusterZone(NetZone* father, const char* name) : NetZoneImpl(father, name)
23 void ClusterZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t route, double* lat)
25 XBT_VERB("cluster getLocalRoute from '%s'[%d] to '%s'[%d]", src->cname(), src->id(), dst->cname(), dst->id());
26 xbt_assert(not privateLinks_.empty(),
27 "Cluster routing: no links attached to the source node - did you use host_link tag?");
29 if ((src->id() == dst->id()) && hasLoopback_) {
30 xbt_assert(not src->isRouter(), "Routing from a cluster private router to itself is meaningless");
32 std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id() * linkCountPerNode_);
33 route->link_list->push_back(info.first);
35 *lat += info.first->latency();
39 if (not src->isRouter()) { // No private link for the private router
40 if (hasLimiter_) { // limiter for sender
41 std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
42 privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
43 route->link_list->push_back(info.first);
46 std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
47 privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
48 if (info.first) { // link up
49 route->link_list->push_back(info.first);
51 *lat += info.first->latency();
56 route->link_list->push_back(backbone_);
58 *lat += backbone_->latency();
61 if (not dst->isRouter()) { // No specific link for router
63 std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
64 privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
65 if (info.second) { // link down
66 route->link_list->push_back(info.second);
68 *lat += info.second->latency();
70 if (hasLimiter_) { // limiter for receiver
71 info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
72 route->link_list->push_back(info.first);
77 void ClusterZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
80 "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_->cname(), nodes);
85 xbt_node_t backboneNode = nullptr;
87 backboneNode = new_xbt_graph_node(graph, backbone_->cname(), nodes);
88 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
91 for (auto src : vertices_) {
92 if (not src->isRouter()) {
93 xbt_node_t previous = new_xbt_graph_node(graph, src->cname(), nodes);
95 std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id());
97 if (info.first) { // link up
98 xbt_node_t current = new_xbt_graph_node(graph, info.first->cname(), nodes);
99 new_xbt_graph_edge(graph, previous, current, edges);
102 new_xbt_graph_edge(graph, current, backboneNode, edges);
104 new_xbt_graph_edge(graph, current, routerNode, edges);
108 if (info.second) { // link down
109 xbt_node_t current = new_xbt_graph_node(graph, info.second->cname(), nodes);
110 new_xbt_graph_edge(graph, previous, current, edges);
113 new_xbt_graph_edge(graph, current, backboneNode, edges);
115 new_xbt_graph_edge(graph, current, routerNode, edges);
122 void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int /*rank*/, int position)
124 char* link_id = bprintf("%s_link_%d", cluster->id, id);
126 LinkCreationArgs link;
128 link.bandwidth = cluster->bw;
129 link.latency = cluster->lat;
130 link.policy = cluster->sharing_policy;
131 sg_platf_new_link(&link);
133 surf::LinkImpl *linkUp;
134 surf::LinkImpl *linkDown;
135 if (link.policy == SURF_LINK_FULLDUPLEX) {
136 char* tmp_link = bprintf("%s_UP", link_id);
137 linkUp = surf::LinkImpl::byName(tmp_link);
139 tmp_link = bprintf("%s_DOWN", link_id);
140 linkDown = surf::LinkImpl::byName(tmp_link);
143 linkUp = surf::LinkImpl::byName(link_id);
147 privateLinks_.insert({position, {linkUp, linkDown}});