Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[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, 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     xbt_assert(not src->is_router(), "Routing from a cluster private router to itself is meaningless");
33
34     std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos(src->id()));
35     route->link_list.push_back(info.first);
36     if (lat)
37       *lat += info.first->get_latency();
38     return;
39   }
40
41   if (not src->is_router()) { // No private link for the private router
42     if (has_limiter_) {      // limiter for sender
43       std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback(src->id()));
44       route->link_list.push_back(info.first);
45     }
46
47     std::pair<resource::LinkImpl*, resource::LinkImpl*> info =
48         private_links_.at(node_pos_with_loopback_limiter(src->id()));
49     if (info.first) { // link up
50       route->link_list.push_back(info.first);
51       if (lat)
52         *lat += info.first->get_latency();
53     }
54   }
55
56   if (backbone_) {
57     route->link_list.push_back(backbone_);
58     if (lat)
59       *lat += backbone_->get_latency();
60   }
61
62   if (not dst->is_router()) { // No specific link for router
63
64     std::pair<resource::LinkImpl*, resource::LinkImpl*> info =
65         private_links_.at(node_pos_with_loopback_limiter(dst->id()));
66     if (info.second) { // link down
67       route->link_list.push_back(info.second);
68       if (lat)
69         *lat += info.second->get_latency();
70     }
71     if (has_limiter_) { // limiter for receiver
72       info = private_links_.at(node_pos_with_loopback(dst->id()));
73       route->link_list.push_back(info.first);
74     }
75   }
76 }
77
78 void ClusterZone::get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
79                             std::map<std::string, xbt_edge_t>* edges)
80 {
81   xbt_assert(router_,
82              "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
83
84   /* create the router */
85   xbt_node_t routerNode = new_xbt_graph_node(graph, router_->get_cname(), nodes);
86
87   xbt_node_t backboneNode = nullptr;
88   if (backbone_) {
89     backboneNode = new_xbt_graph_node(graph, backbone_->get_cname(), nodes);
90     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
91   }
92
93   for (auto const& src : get_vertices()) {
94     if (not src->is_router()) {
95       xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes);
96
97       std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(src->id());
98
99       if (info.first) { // link up
100         xbt_node_t current = new_xbt_graph_node(graph, info.first->get_cname(), nodes);
101         new_xbt_graph_edge(graph, previous, current, edges);
102
103         if (backbone_) {
104           new_xbt_graph_edge(graph, current, backboneNode, edges);
105         } else {
106           new_xbt_graph_edge(graph, current, routerNode, edges);
107         }
108       }
109
110       if (info.second) { // link down
111         xbt_node_t current = new_xbt_graph_node(graph, info.second->get_cname(), nodes);
112         new_xbt_graph_edge(graph, previous, current, edges);
113
114         if (backbone_) {
115           new_xbt_graph_edge(graph, current, backboneNode, edges);
116         } else {
117           new_xbt_graph_edge(graph, current, routerNode, edges);
118         }
119       }
120     }
121   }
122 }
123
124 void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int /*rank*/, unsigned int position)
125 {
126   std::string link_id = cluster->id + "_link_" + std::to_string(id);
127
128   LinkCreationArgs link;
129   link.id        = link_id;
130   link.bandwidth = cluster->bw;
131   link.latency   = cluster->lat;
132   link.policy    = cluster->sharing_policy;
133   sg_platf_new_link(&link);
134
135   s4u::Link* linkUp;
136   s4u::Link* linkDown;
137   if (link.policy == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) {
138     linkUp   = s4u::Link::by_name(link_id + "_UP");
139     linkDown = s4u::Link::by_name(link_id + "_DOWN");
140   } else {
141     linkUp   = s4u::Link::by_name(link_id);
142     linkDown = linkUp;
143   }
144   private_links_.insert({position, {linkUp->get_impl(), linkDown->get_impl()}});
145 }
146 }
147 }
148 }