Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
stop loading private headers from now public NetZoneImpl.hpp
[simgrid.git] / src / kernel / routing / ClusterZone.cpp
1 /* Copyright (c) 2009-2018. 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(NetZone* father, std::string name) : NetZoneImpl(father, name)
21 {
22 }
23
24 void ClusterZone::getLocalRoute(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat)
25 {
26   XBT_VERB("cluster getLocalRoute from '%s'[%u] to '%s'[%u]", src->getCname(), src->id(), dst->getCname(), dst->id());
27   xbt_assert(not privateLinks_.empty(),
28              "Cluster routing: no links attached to the source node - did you use host_link tag?");
29
30   if ((src->id() == dst->id()) && hasLoopback_) {
31     xbt_assert(not src->isRouter(), "Routing from a cluster private router to itself is meaningless");
32
33     std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(nodePosition(src->id()));
34     route->link_list.push_back(info.first);
35     if (lat)
36       *lat += info.first->latency();
37     return;
38   }
39
40   if (not src->isRouter()) { // No private link for the private router
41     if (hasLimiter_) { // limiter for sender
42       std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(nodePositionWithLoopback(src->id()));
43       route->link_list.push_back(info.first);
44     }
45
46     std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(nodePositionWithLimiter(src->id()));
47     if (info.first) { // link up
48       route->link_list.push_back(info.first);
49       if (lat)
50         *lat += info.first->latency();
51     }
52   }
53
54   if (backbone_) {
55     route->link_list.push_back(backbone_);
56     if (lat)
57       *lat += backbone_->latency();
58   }
59
60   if (not dst->isRouter()) { // No specific link for router
61
62     std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(nodePositionWithLimiter(dst->id()));
63     if (info.second) { // link down
64       route->link_list.push_back(info.second);
65       if (lat)
66         *lat += info.second->latency();
67     }
68     if (hasLimiter_) { // limiter for receiver
69       info = privateLinks_.at(nodePositionWithLoopback(dst->id()));
70       route->link_list.push_back(info.first);
71     }
72   }
73 }
74
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)
77 {
78   xbt_assert(router_,
79              "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
80
81   /* create the router */
82   xbt_node_t routerNode = new_xbt_graph_node(graph, router_->getCname(), nodes);
83
84   xbt_node_t backboneNode = nullptr;
85   if (backbone_) {
86     backboneNode = new_xbt_graph_node(graph, backbone_->getCname(), nodes);
87     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
88   }
89
90   for (auto const& src : getVertices()) {
91     if (not src->isRouter()) {
92       xbt_node_t previous = new_xbt_graph_node(graph, src->getCname(), nodes);
93
94       std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id());
95
96       if (info.first) { // link up
97         xbt_node_t current = new_xbt_graph_node(graph, info.first->getCname(), nodes);
98         new_xbt_graph_edge(graph, previous, current, edges);
99
100         if (backbone_) {
101           new_xbt_graph_edge(graph, current, backboneNode, edges);
102         } else {
103           new_xbt_graph_edge(graph, current, routerNode, edges);
104         }
105       }
106
107       if (info.second) { // link down
108         xbt_node_t current = new_xbt_graph_node(graph, info.second->getCname(), nodes);
109         new_xbt_graph_edge(graph, previous, current, edges);
110
111         if (backbone_) {
112           new_xbt_graph_edge(graph, current, backboneNode, edges);
113         } else {
114           new_xbt_graph_edge(graph, current, routerNode, edges);
115         }
116       }
117     }
118   }
119 }
120
121 void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int /*rank*/, unsigned int position)
122 {
123   std::string link_id = cluster->id + "_link_" + std::to_string(id);
124
125   LinkCreationArgs link;
126   link.id        = link_id;
127   link.bandwidth = cluster->bw;
128   link.latency   = cluster->lat;
129   link.policy    = cluster->sharing_policy;
130   sg_platf_new_link(&link);
131
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");
137   } else {
138     linkUp   = surf::LinkImpl::byName(link_id);
139     linkDown = linkUp;
140   }
141   privateLinks_.insert({position, {linkUp, linkDown}});
142 }
143 }
144 }
145 }