Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change cname() to getCname() and add getName() in surf::Resource.
[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->getCname(), src->id(), dst->getCname(), 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(nodePosition(src->id()));
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 = privateLinks_.at(nodePositionWithLoopback(src->id()));
42       route->link_list->push_back(info.first);
43     }
44
45     std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(nodePositionWithLimiter(src->id()));
46     if (info.first) { // link up
47       route->link_list->push_back(info.first);
48       if (lat)
49         *lat += info.first->latency();
50     }
51   }
52
53   if (backbone_) {
54     route->link_list->push_back(backbone_);
55     if (lat)
56       *lat += backbone_->latency();
57   }
58
59   if (not dst->isRouter()) { // No specific link for router
60
61     std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(nodePositionWithLimiter(dst->id()));
62     if (info.second) { // link down
63       route->link_list->push_back(info.second);
64       if (lat)
65         *lat += info.second->latency();
66     }
67     if (hasLimiter_) { // limiter for receiver
68       info = privateLinks_.at(nodePositionWithLoopback(dst->id()));
69       route->link_list->push_back(info.first);
70     }
71   }
72 }
73
74 void ClusterZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
75 {
76   xbt_assert(router_,
77              "Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
78
79   /* create the router */
80   xbt_node_t routerNode = new_xbt_graph_node(graph, router_->getCname(), nodes);
81
82   xbt_node_t backboneNode = nullptr;
83   if (backbone_) {
84     backboneNode = new_xbt_graph_node(graph, backbone_->getCname(), nodes);
85     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
86   }
87
88   for (auto const& src : getVertices()) {
89     if (not src->isRouter()) {
90       xbt_node_t previous = new_xbt_graph_node(graph, src->getCname(), nodes);
91
92       std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id());
93
94       if (info.first) { // link up
95         xbt_node_t current = new_xbt_graph_node(graph, info.first->getCname(), nodes);
96         new_xbt_graph_edge(graph, previous, current, edges);
97
98         if (backbone_) {
99           new_xbt_graph_edge(graph, current, backboneNode, edges);
100         } else {
101           new_xbt_graph_edge(graph, current, routerNode, edges);
102         }
103       }
104
105       if (info.second) { // link down
106         xbt_node_t current = new_xbt_graph_node(graph, info.second->getCname(), nodes);
107         new_xbt_graph_edge(graph, previous, current, edges);
108
109         if (backbone_) {
110           new_xbt_graph_edge(graph, current, backboneNode, edges);
111         } else {
112           new_xbt_graph_edge(graph, current, routerNode, edges);
113         }
114       }
115     }
116   }
117 }
118
119 void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int /*rank*/, int position)
120 {
121   std::string link_id = cluster->id + "_link_" + std::to_string(id);
122
123   LinkCreationArgs link;
124   link.id        = link_id;
125   link.bandwidth = cluster->bw;
126   link.latency   = cluster->lat;
127   link.policy    = cluster->sharing_policy;
128   sg_platf_new_link(&link);
129
130   surf::LinkImpl *linkUp;
131   surf::LinkImpl *linkDown;
132   if (link.policy == SURF_LINK_FULLDUPLEX) {
133     linkUp   = surf::LinkImpl::byName(link_id + "_UP");
134     linkDown = surf::LinkImpl::byName(link_id + "_DOWN");
135   } else {
136     linkUp   = surf::LinkImpl::byName(link_id);
137     linkDown = linkUp;
138   }
139   privateLinks_.insert({position, {linkUp, linkDown}});
140 }
141 }
142 }
143 }