Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improve the routing documentation
[simgrid.git] / src / kernel / routing / ClusterZone.cpp
1 /* Copyright (c) 2009-2016. 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/NetCard.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, const char* name) : NetZoneImpl(father, name)
20 {
21 }
22
23 void ClusterZone::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_t route, double* lat)
24 {
25   XBT_VERB("cluster getLocalRoute from '%s'[%d] to '%s'[%d]", src->cname(), src->id(), dst->cname(), dst->id());
26   xbt_assert(!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(!src->isRouter(), "Routing from a cluster private router to itself is meaningless");
31
32     std::pair<Link*, Link*> 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 (!src->isRouter()) { // No private link for the private router
40     if (hasLimiter_) { // limiter for sender
41       std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
42       route->link_list->push_back(info.first);
43     }
44
45     std::pair<Link*, Link*> info =
46         privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
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 (!dst->isRouter()) { // No specific link for router
61
62     std::pair<Link*, Link*> info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
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(dst->id() * linkCountPerNode_ + hasLoopback_);
70       route->link_list->push_back(info.first);
71     }
72   }
73 }
74
75 void ClusterZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
76 {
77   xbt_assert(router_,
78              "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
79
80   /* create the router */
81   xbt_node_t routerNode = new_xbt_graph_node(graph, router_->cname(), nodes);
82
83   xbt_node_t backboneNode = nullptr;
84   if (backbone_) {
85     backboneNode = new_xbt_graph_node(graph, backbone_->getName(), nodes);
86     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
87   }
88
89   for (auto src : vertices_) {
90     if (!src->isRouter()) {
91       xbt_node_t previous = new_xbt_graph_node(graph, src->cname(), nodes);
92
93       std::pair<Link*, Link*> info = privateLinks_.at(src->id());
94
95       if (info.first) { // link up
96         xbt_node_t current = new_xbt_graph_node(graph, info.first->getName(), nodes);
97         new_xbt_graph_edge(graph, previous, current, edges);
98
99         if (backbone_) {
100           new_xbt_graph_edge(graph, current, backboneNode, edges);
101         } else {
102           new_xbt_graph_edge(graph, current, routerNode, edges);
103         }
104       }
105
106       if (info.second) { // link down
107         xbt_node_t current = new_xbt_graph_node(graph, info.second->getName(), nodes);
108         new_xbt_graph_edge(graph, previous, current, edges);
109
110         if (backbone_) {
111           new_xbt_graph_edge(graph, current, backboneNode, edges);
112         } else {
113           new_xbt_graph_edge(graph, current, routerNode, edges);
114         }
115       }
116     }
117   }
118 }
119
120 void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int /*rank*/, int position)
121 {
122   char* link_id = bprintf("%s_link_%d", cluster->id, id);
123
124   s_sg_platf_link_cbarg_t link;
125   memset(&link, 0, sizeof(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   Link *linkUp, *linkDown;
133   if (link.policy == SURF_LINK_FULLDUPLEX) {
134     char* tmp_link = bprintf("%s_UP", link_id);
135     linkUp         = Link::byName(tmp_link);
136     xbt_free(tmp_link);
137     tmp_link = bprintf("%s_DOWN", link_id);
138     linkDown = Link::byName(tmp_link);
139     xbt_free(tmp_link);
140   } else {
141     linkUp   = Link::byName(link_id);
142     linkDown = linkUp;
143   }
144   privateLinks_.insert({position, {linkUp, linkDown}});
145   xbt_free(link_id);
146 }
147 }
148 }
149 }