Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Another try to silence sonar on commented lines of code.
[simgrid.git] / src / kernel / routing / ClusterZone.cpp
1 /* Copyright (c) 2009-2017. 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 "src/kernel/routing/ClusterZone.hpp"
7 #include "src/kernel/routing/NetPoint.hpp"
8 #include "src/kernel/routing/RoutedZone.hpp"
9 #include "src/surf/network_interface.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
12
13 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
14  * Note that a router is created, easing the interconnexion with the rest of the world. */
15
16 namespace simgrid {
17 namespace kernel {
18 namespace routing {
19 ClusterZone::ClusterZone(NetZone* father, std::string name) : NetZoneImpl(father, name)
20 {
21 }
22
23 void ClusterZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t route, double* lat)
24 {
25   XBT_VERB("cluster getLocalRoute from '%s'[%u] to '%s'[%u]", src->cname(), src->id(), dst->cname(), dst->id());
26   xbt_assert(not privateLinks_.empty(),
27              "Cluster routing: no links attached to the source node - did you use host_link tag?");
28
29   if ((src->id() == dst->id()) && hasLoopback_) {
30     xbt_assert(not src->isRouter(), "Routing from a cluster private router to itself is meaningless");
31
32     std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id() * linkCountPerNode_);
33     route->link_list->push_back(info.first);
34     if (lat)
35       *lat += info.first->latency();
36     return;
37   }
38
39   if (not src->isRouter()) { // No private link for the private router
40     if (hasLimiter_) { // limiter for sender
41       std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
42           privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
43       route->link_list->push_back(info.first);
44     }
45
46     std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
47         privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
48     if (info.first) { // link up
49       route->link_list->push_back(info.first);
50       if (lat)
51         *lat += info.first->latency();
52     }
53   }
54
55   if (backbone_) {
56     route->link_list->push_back(backbone_);
57     if (lat)
58       *lat += backbone_->latency();
59   }
60
61   if (not dst->isRouter()) { // No specific link for router
62
63     std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
64         privateLinks_.at(dst->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
65     if (info.second) { // link down
66       route->link_list->push_back(info.second);
67       if (lat)
68         *lat += info.second->latency();
69     }
70     if (hasLimiter_) { // limiter for receiver
71       info = privateLinks_.at(dst->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
72       route->link_list->push_back(info.first);
73     }
74   }
75 }
76
77 void ClusterZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
78 {
79   xbt_assert(router_,
80              "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
81
82   /* create the router */
83   xbt_node_t routerNode = new_xbt_graph_node(graph, router_->cname(), nodes);
84
85   xbt_node_t backboneNode = nullptr;
86   if (backbone_) {
87     backboneNode = new_xbt_graph_node(graph, backbone_->cname(), nodes);
88     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
89   }
90
91   for (auto const& src : getVertices()) {
92     if (not src->isRouter()) {
93       xbt_node_t previous = new_xbt_graph_node(graph, src->cname(), nodes);
94
95       std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id());
96
97       if (info.first) { // link up
98         xbt_node_t current = new_xbt_graph_node(graph, info.first->cname(), nodes);
99         new_xbt_graph_edge(graph, previous, current, edges);
100
101         if (backbone_) {
102           new_xbt_graph_edge(graph, current, backboneNode, edges);
103         } else {
104           new_xbt_graph_edge(graph, current, routerNode, edges);
105         }
106       }
107
108       if (info.second) { // link down
109         xbt_node_t current = new_xbt_graph_node(graph, info.second->cname(), nodes);
110         new_xbt_graph_edge(graph, previous, current, edges);
111
112         if (backbone_) {
113           new_xbt_graph_edge(graph, current, backboneNode, edges);
114         } else {
115           new_xbt_graph_edge(graph, current, routerNode, edges);
116         }
117       }
118     }
119   }
120 }
121
122 void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int /*rank*/, int position)
123 {
124   std::string link_id = cluster->id + "_link_" + std::to_string(id);
125
126   LinkCreationArgs link;
127   link.id        = link_id;
128   link.bandwidth = cluster->bw;
129   link.latency   = cluster->lat;
130   link.policy    = cluster->sharing_policy;
131   sg_platf_new_link(&link);
132
133   surf::LinkImpl *linkUp;
134   surf::LinkImpl *linkDown;
135   if (link.policy == SURF_LINK_FULLDUPLEX) {
136     linkUp   = surf::LinkImpl::byName(link_id + "_UP");
137     linkDown = surf::LinkImpl::byName(link_id + "_DOWN");
138   } else {
139     linkUp   = surf::LinkImpl::byName(link_id);
140     linkDown = linkUp;
141   }
142   privateLinks_.insert({position, {linkUp, linkDown}});
143 }
144 }
145 }
146 }