Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / kernel / routing / AsCluster.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/AsCluster.hpp"
7 #include "src/surf/network_interface.hpp"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
10
11 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
12  * Note that a router is created, easing the interconnexion with the rest of the world. */
13
14 namespace simgrid {
15 namespace kernel {
16 namespace routing {
17   AsCluster::AsCluster(const char*name)
18     : AsImpl(name)
19   {}
20   AsCluster::~AsCluster()=default;
21
22 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
23 {
24   s_surf_parsing_link_up_down_t info;
25   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
26             src->name(), src->id(), dst->name(), dst->id());
27   xbt_assert(!privateLinks_.empty(), "Cluster routing : no links attached to the source node - did you use host_link tag?");
28   if (! src->isRouter()) {    // No specific link for router
29
30     if((src->id() == dst->id()) && hasLoopback_ ){
31       info = privateLinks_.at(src->id() * linkCountPerNode_);
32       route->link_list->push_back(info.linkUp);
33       if (lat)
34         *lat += info.linkUp->getLatency();
35       return;
36     }
37
38
39     if (hasLimiter_){          // limiter for sender
40       info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_?1:0));
41       route->link_list->push_back((Link*)info.linkUp);
42     }
43
44     info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_?1:0) + (hasLimiter_?1:0));
45     if (info.linkUp) {         // link up
46       route->link_list->push_back(info.linkUp);
47       if (lat)
48         *lat += info.linkUp->getLatency();
49     }
50
51   }
52
53   if (backbone_) {
54     route->link_list->push_back(backbone_);
55     if (lat)
56       *lat += backbone_->getLatency();
57   }
58
59   if (! dst->isRouter()) {    // No specific link for router
60     info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
61
62     if (info.linkDown) {       // link down
63       route->link_list->push_back(info.linkDown);
64       if (lat)
65         *lat += info.linkDown->getLatency();
66     }
67     if (hasLimiter_){          // limiter for receiver
68         info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
69         route->link_list->push_back(info.linkUp);
70     }
71   }
72 }
73
74 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
75 {
76   xbt_node_t current, previous, backboneNode = nullptr, routerNode;
77   s_surf_parsing_link_up_down_t info;
78
79   xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
80
81   /* create the router */
82   char *link_name = router_->name();
83   routerNode = new_xbt_graph_node(graph, link_name, nodes);
84
85   if(backbone_) {
86     const char *link_nameR = backbone_->getName();
87     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
88
89     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
90   }
91
92   for (auto src: vertices_){
93     if (! src->isRouter()) {
94       previous = new_xbt_graph_node(graph, src->name(), nodes);
95
96       info = privateLinks_.at(src->id());
97
98       if (info.linkUp) {     // link up
99         const char *link_name = static_cast<simgrid::surf::Resource*>(info.linkUp)->getName();
100         current = new_xbt_graph_node(graph, link_name, 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.linkDown) {    // link down
111         const char *link_name = static_cast<simgrid::surf::Resource*>(
112           info.linkDown)->getName();
113         current = new_xbt_graph_node(graph, link_name, nodes);
114         new_xbt_graph_edge(graph, previous, current, edges);
115
116         if (backbone_) {
117           new_xbt_graph_edge(graph, current, backboneNode, edges);
118         } else {
119           new_xbt_graph_edge(graph, current, routerNode, edges);
120         }
121       }
122     }
123   }
124 }
125
126 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
127   s_surf_parsing_link_up_down_t info;
128   char* link_id = bprintf("%s_link_%d", cluster->id, id);
129
130   s_sg_platf_link_cbarg_t link;
131   memset(&link, 0, sizeof(link));
132   link.id = link_id;
133   link.bandwidth = cluster->bw;
134   link.latency = cluster->lat;
135   link.policy = cluster->sharing_policy;
136   sg_platf_new_link(&link);
137
138   if (link.policy == SURF_LINK_FULLDUPLEX) {
139     char *tmp_link = bprintf("%s_UP", link_id);
140     info.linkUp = Link::byName(tmp_link);
141     xbt_free(tmp_link);
142     tmp_link = bprintf("%s_DOWN", link_id);
143     info.linkDown = Link::byName(tmp_link);
144     xbt_free(tmp_link);
145   } else {
146     info.linkUp = Link::byName(link_id);
147     info.linkDown = info.linkUp;
148   }
149   privateLinks_.insert(privateLinks_.begin()+position, info);
150   xbt_free(link_id);
151 }
152
153 }}}