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/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 ClusterZone::ClusterZone(NetZone* father, const char* name) : NetZoneImpl(father, name)
22 void ClusterZone::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->cname(), src->id(), dst->cname(), dst->id());
25 xbt_assert(!privateLinks_.empty(),
26 "Cluster routing: no links attached to the source node - did you use host_link tag?");
28 if (!src->isRouter()) { // No specific link for router
30 if ((src->id() == dst->id()) && hasLoopback_) {
31 std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_);
32 route->link_list->push_back(info.first);
34 *lat += info.first->latency();
38 if (hasLimiter_) { // limiter for sender
39 std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
40 route->link_list->push_back(info.first);
43 std::pair<Link*, Link*> info =
44 privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
45 if (info.first) { // link up
46 route->link_list->push_back(info.first);
48 *lat += info.first->latency();
53 route->link_list->push_back(backbone_);
55 *lat += backbone_->latency();
58 if (!dst->isRouter()) { // No specific link for router
59 std::pair<Link*, Link*> info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
61 if (info.second) { // link down
62 route->link_list->push_back(info.second);
64 *lat += info.second->latency();
66 if (hasLimiter_) { // limiter for receiver
67 info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
68 route->link_list->push_back(info.first);
73 void ClusterZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
76 "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
78 /* create the router */
79 xbt_node_t routerNode = new_xbt_graph_node(graph, router_->cname(), nodes);
81 xbt_node_t backboneNode = nullptr;
83 backboneNode = new_xbt_graph_node(graph, backbone_->getName(), nodes);
84 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
87 for (auto src : vertices_) {
88 if (!src->isRouter()) {
89 xbt_node_t previous = new_xbt_graph_node(graph, src->cname(), nodes);
91 std::pair<Link*, Link*> info = privateLinks_.at(src->id());
93 if (info.first) { // link up
94 xbt_node_t current = new_xbt_graph_node(graph, info.first->getName(), nodes);
95 new_xbt_graph_edge(graph, previous, current, edges);
98 new_xbt_graph_edge(graph, current, backboneNode, edges);
100 new_xbt_graph_edge(graph, current, routerNode, edges);
104 if (info.second) { // link down
105 xbt_node_t current = new_xbt_graph_node(graph, info.second->getName(), nodes);
106 new_xbt_graph_edge(graph, previous, current, edges);
109 new_xbt_graph_edge(graph, current, backboneNode, edges);
111 new_xbt_graph_edge(graph, current, routerNode, edges);
118 void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int, int position)
120 char* link_id = bprintf("%s_link_%d", cluster->id, id);
122 s_sg_platf_link_cbarg_t link;
123 memset(&link, 0, sizeof(link));
125 link.bandwidth = cluster->bw;
126 link.latency = cluster->lat;
127 link.policy = cluster->sharing_policy;
128 sg_platf_new_link(&link);
130 Link *linkUp, *linkDown;
131 if (link.policy == SURF_LINK_FULLDUPLEX) {
132 char* tmp_link = bprintf("%s_UP", link_id);
133 linkUp = Link::byName(tmp_link);
135 tmp_link = bprintf("%s_DOWN", link_id);
136 linkDown = Link::byName(tmp_link);
139 linkUp = Link::byName(link_id);
142 privateLinks_.insert({position, {linkUp, linkDown}});