Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e49e486ba24c6dff965b879f117032528d019e4f
[simgrid.git] / src / kernel / routing / ClusterZone.cpp
1 /* Copyright (c) 2009-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
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
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
13
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. */
16
17 namespace simgrid {
18 namespace kernel {
19 namespace routing {
20 ClusterZone::ClusterZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
21     : NetZoneImpl(father, name, netmodel)
22 {
23 }
24
25 void ClusterZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat)
26 {
27   XBT_VERB("cluster getLocalRoute from '%s'[%u] to '%s'[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
28   xbt_assert(not private_links_.empty(),
29              "Cluster routing: no links attached to the source node - did you use host_link tag?");
30
31   if ((src->id() == dst->id()) && has_loopback_) {
32     if (src->is_router()) {
33       XBT_WARN("Routing from a cluster private router to itself is meaningless");
34     } else {
35       std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos(src->id()));
36       route->link_list.push_back(info.first);
37       if (lat)
38         *lat += info.first->get_latency();
39     }
40     return;
41   }
42
43   if (not src->is_router()) { // No private link for the private router
44     if (has_limiter_) {      // limiter for sender
45       std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback(src->id()));
46       route->link_list.push_back(info.first);
47     }
48
49     std::pair<resource::LinkImpl*, resource::LinkImpl*> info =
50         private_links_.at(node_pos_with_loopback_limiter(src->id()));
51     if (info.first) { // link up
52       route->link_list.push_back(info.first);
53       if (lat)
54         *lat += info.first->get_latency();
55     }
56   }
57
58   if (backbone_) {
59     route->link_list.push_back(backbone_);
60     if (lat)
61       *lat += backbone_->get_latency();
62   }
63
64   if (not dst->is_router()) { // No specific link for router
65
66     std::pair<resource::LinkImpl*, resource::LinkImpl*> info =
67         private_links_.at(node_pos_with_loopback_limiter(dst->id()));
68     if (info.second) { // link down
69       route->link_list.push_back(info.second);
70       if (lat)
71         *lat += info.second->get_latency();
72     }
73     if (has_limiter_) { // limiter for receiver
74       info = private_links_.at(node_pos_with_loopback(dst->id()));
75       route->link_list.push_back(info.first);
76     }
77   }
78 }
79
80 void ClusterZone::get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
81                             std::map<std::string, xbt_edge_t>* edges)
82 {
83   xbt_assert(router_,
84              "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
85
86   /* create the router */
87   xbt_node_t routerNode = new_xbt_graph_node(graph, router_->get_cname(), nodes);
88
89   xbt_node_t backboneNode = nullptr;
90   if (backbone_) {
91     backboneNode = new_xbt_graph_node(graph, backbone_->get_cname(), nodes);
92     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
93   }
94
95   for (auto const& src : get_vertices()) {
96     if (not src->is_router()) {
97       xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes);
98
99       std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(src->id());
100
101       if (info.first) { // link up
102         xbt_node_t current = new_xbt_graph_node(graph, info.first->get_cname(), nodes);
103         new_xbt_graph_edge(graph, previous, current, edges);
104
105         if (backbone_) {
106           new_xbt_graph_edge(graph, current, backboneNode, edges);
107         } else {
108           new_xbt_graph_edge(graph, current, routerNode, edges);
109         }
110       }
111
112       if (info.second) { // link down
113         xbt_node_t current = new_xbt_graph_node(graph, info.second->get_cname(), nodes);
114         new_xbt_graph_edge(graph, previous, current, edges);
115
116         if (backbone_) {
117           new_xbt_graph_edge(graph, current, backboneNode, edges);
118         } else {
119           new_xbt_graph_edge(graph, current, routerNode, edges);
120         }
121       }
122     }
123   }
124 }
125
126 void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int /*rank*/, unsigned int position)
127 {
128   std::string link_id = cluster->id + "_link_" + std::to_string(id);
129
130   LinkCreationArgs link;
131   link.id        = link_id;
132   link.bandwidth = cluster->bw;
133   link.latency   = cluster->lat;
134   link.policy    = cluster->sharing_policy;
135   sg_platf_new_link(&link);
136
137   s4u::Link* linkUp;
138   s4u::Link* linkDown;
139   if (link.policy == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) {
140     linkUp   = s4u::Link::by_name(link_id + "_UP");
141     linkDown = s4u::Link::by_name(link_id + "_DOWN");
142   } else {
143     linkUp   = s4u::Link::by_name(link_id);
144     linkDown = linkUp;
145   }
146   private_links_.insert({position, {linkUp->get_impl(), linkDown->get_impl()}});
147 }
148 }
149 }
150 }