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/NetCard.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(NetCard* src, NetCard* 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(!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 std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_);
33 route->link_list->push_back(info.first);
35 *lat += info.first->latency();
39 if (hasLimiter_) { // limiter for sender
40 std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
41 route->link_list->push_back(info.first);
44 std::pair<Link*, Link*> info =
45 privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
46 if (info.first) { // link up
47 route->link_list->push_back(info.first);
49 *lat += info.first->latency();
54 route->link_list->push_back(backbone_);
56 *lat += backbone_->latency();
59 if (!dst->isRouter()) { // No specific link for router
60 std::pair<Link*, Link*> info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
62 if (info.second) { // link down
63 route->link_list->push_back(info.second);
65 *lat += info.second->latency();
67 if (hasLimiter_) { // limiter for receiver
68 info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
69 route->link_list->push_back(info.first);
74 void ClusterZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
77 "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
79 /* create the router */
80 xbt_node_t routerNode = new_xbt_graph_node(graph, router_->cname(), nodes);
82 xbt_node_t backboneNode = nullptr;
84 backboneNode = new_xbt_graph_node(graph, backbone_->getName(), nodes);
85 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
88 for (auto src : vertices_) {
89 if (!src->isRouter()) {
90 xbt_node_t previous = new_xbt_graph_node(graph, src->cname(), nodes);
92 std::pair<Link*, Link*> info = privateLinks_.at(src->id());
94 if (info.first) { // link up
95 xbt_node_t current = new_xbt_graph_node(graph, info.first->getName(), nodes);
96 new_xbt_graph_edge(graph, previous, current, edges);
99 new_xbt_graph_edge(graph, current, backboneNode, edges);
101 new_xbt_graph_edge(graph, current, routerNode, edges);
105 if (info.second) { // link down
106 xbt_node_t current = new_xbt_graph_node(graph, info.second->getName(), nodes);
107 new_xbt_graph_edge(graph, previous, current, edges);
110 new_xbt_graph_edge(graph, current, backboneNode, edges);
112 new_xbt_graph_edge(graph, current, routerNode, edges);
119 void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int, int position)
121 char* link_id = bprintf("%s_link_%d", cluster->id, id);
123 s_sg_platf_link_cbarg_t link;
124 memset(&link, 0, sizeof(link));
126 link.bandwidth = cluster->bw;
127 link.latency = cluster->lat;
128 link.policy = cluster->sharing_policy;
129 sg_platf_new_link(&link);
131 Link *linkUp, *linkDown;
132 if (link.policy == SURF_LINK_FULLDUPLEX) {
133 char* tmp_link = bprintf("%s_UP", link_id);
134 linkUp = Link::byName(tmp_link);
136 tmp_link = bprintf("%s_DOWN", link_id);
137 linkDown = Link::byName(tmp_link);
140 linkUp = Link::byName(link_id);
143 privateLinks_.insert({position, {linkUp, linkDown}});