1 /* Copyright (c) 2009-2018. 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 "simgrid/kernel/routing/ClusterZone.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "simgrid/kernel/routing/RoutedZone.hpp"
9 #include "src/surf/network_interface.hpp"
10 #include "src/surf/xml/platf_private.hpp" // FIXME: RouteCreationArgs and friends
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
14 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
15 * Note that a router is created, easing the interconnexion with the rest of the world. */
20 ClusterZone::ClusterZone(NetZone* father, std::string name) : NetZoneImpl(father, name)
24 void ClusterZone::getLocalRoute(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat)
26 XBT_VERB("cluster getLocalRoute from '%s'[%u] to '%s'[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
27 xbt_assert(not private_links_.empty(),
28 "Cluster routing: no links attached to the source node - did you use host_link tag?");
30 if ((src->id() == dst->id()) && has_loopback_) {
31 xbt_assert(not src->isRouter(), "Routing from a cluster private router to itself is meaningless");
33 std::pair<surf::LinkImpl*, surf::LinkImpl*> info = private_links_.at(nodePosition(src->id()));
34 route->link_list.push_back(info.first);
36 *lat += info.first->latency();
40 if (not src->isRouter()) { // No private link for the private router
41 if (has_limiter_) { // limiter for sender
42 std::pair<surf::LinkImpl*, surf::LinkImpl*> info = private_links_.at(nodePositionWithLoopback(src->id()));
43 route->link_list.push_back(info.first);
46 std::pair<surf::LinkImpl*, surf::LinkImpl*> info = private_links_.at(nodePositionWithLimiter(src->id()));
47 if (info.first) { // link up
48 route->link_list.push_back(info.first);
50 *lat += info.first->latency();
55 route->link_list.push_back(backbone_);
57 *lat += backbone_->latency();
60 if (not dst->isRouter()) { // No specific link for router
62 std::pair<surf::LinkImpl*, surf::LinkImpl*> info = private_links_.at(nodePositionWithLimiter(dst->id()));
63 if (info.second) { // link down
64 route->link_list.push_back(info.second);
66 *lat += info.second->latency();
68 if (has_limiter_) { // limiter for receiver
69 info = private_links_.at(nodePositionWithLoopback(dst->id()));
70 route->link_list.push_back(info.first);
75 void ClusterZone::getGraph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
76 std::map<std::string, xbt_edge_t>* edges)
79 "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_->get_cname(), nodes);
84 xbt_node_t backboneNode = nullptr;
86 backboneNode = new_xbt_graph_node(graph, backbone_->get_cname(), nodes);
87 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
90 for (auto const& src : getVertices()) {
91 if (not src->isRouter()) {
92 xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes);
94 std::pair<surf::LinkImpl*, surf::LinkImpl*> info = private_links_.at(src->id());
96 if (info.first) { // link up
97 xbt_node_t current = new_xbt_graph_node(graph, info.first->get_cname(), nodes);
98 new_xbt_graph_edge(graph, previous, current, edges);
101 new_xbt_graph_edge(graph, current, backboneNode, edges);
103 new_xbt_graph_edge(graph, current, routerNode, edges);
107 if (info.second) { // link down
108 xbt_node_t current = new_xbt_graph_node(graph, info.second->get_cname(), nodes);
109 new_xbt_graph_edge(graph, previous, current, edges);
112 new_xbt_graph_edge(graph, current, backboneNode, edges);
114 new_xbt_graph_edge(graph, current, routerNode, edges);
121 void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int /*rank*/, unsigned int position)
123 std::string link_id = cluster->id + "_link_" + std::to_string(id);
125 LinkCreationArgs link;
127 link.bandwidth = cluster->bw;
128 link.latency = cluster->lat;
129 link.policy = cluster->sharing_policy;
130 sg_platf_new_link(&link);
132 surf::LinkImpl *linkUp;
133 surf::LinkImpl *linkDown;
134 if (link.policy == SURF_LINK_SPLITDUPLEX) {
135 linkUp = surf::LinkImpl::byName(link_id + "_UP");
136 linkDown = surf::LinkImpl::byName(link_id + "_DOWN");
138 linkUp = surf::LinkImpl::byName(link_id);
141 private_links_.insert({position, {linkUp, linkDown}});