Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move the stack as field of SafetyChecker and CommDetChecker
[simgrid.git] / src / surf / 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/surf/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
15 namespace simgrid {
16 namespace surf {
17   AsCluster::AsCluster(const char*name)
18     : AsImpl(name)
19   {}
20   AsCluster::~AsCluster()
21   {
22     xbt_dynar_free(&privateLinks_);
23   }
24
25 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
26 {
27   s_surf_parsing_link_up_down_t info;
28   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
29             src->name(), src->id(), dst->name(), dst->id());
30
31   if (! src->isRouter()) {    // No specific link for router
32
33     if((src->id() == dst->id()) && has_loopback_  ){
34       info = xbt_dynar_get_as(privateLinks_, src->id() * nb_links_per_node_, s_surf_parsing_link_up_down_t);
35       route->link_list->push_back(info.link_up);
36       if (lat)
37         *lat += info.link_up->getLatency();
38       return;
39     }
40
41
42     if (has_limiter_){          // limiter for sender
43       info = xbt_dynar_get_as(privateLinks_, src->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
44       route->link_list->push_back((Link*)info.link_up);
45     }
46
47     info = xbt_dynar_get_as(privateLinks_, src->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
48     if (info.link_up) {         // link up
49       route->link_list->push_back(info.link_up);
50       if (lat)
51         *lat += info.link_up->getLatency();
52     }
53
54   }
55
56   if (backbone_) {
57     route->link_list->push_back(backbone_);
58     if (lat)
59       *lat += backbone_->getLatency();
60   }
61
62   if (! dst->isRouter()) {    // No specific link for router
63     info = xbt_dynar_get_as(privateLinks_, dst->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
64
65     if (info.link_down) {       // link down
66       route->link_list->push_back(info.link_down);
67       if (lat)
68         *lat += info.link_down->getLatency();
69     }
70     if (has_limiter_){          // limiter for receiver
71         info = xbt_dynar_get_as(privateLinks_, dst->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
72         route->link_list->push_back(info.link_up);
73     }
74   }
75 }
76
77 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
78 {
79   int isrc;
80   int table_size = xbt_dynar_length(vertices_);
81
82   NetCard *src;
83   xbt_node_t current, previous, backboneNode = NULL, routerNode;
84   s_surf_parsing_link_up_down_t info;
85
86   xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
87
88   /* create the router */
89   char *link_name = router_->name();
90   routerNode = new_xbt_graph_node(graph, link_name, nodes);
91
92   if(backbone_) {
93     const char *link_nameR = backbone_->getName();
94     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
95
96     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
97   }
98
99   for (isrc = 0; isrc < table_size; isrc++) {
100     src = xbt_dynar_get_as(vertices_, isrc, NetCard*);
101
102     if (! src->isRouter()) {
103       previous = new_xbt_graph_node(graph, src->name(), nodes);
104
105       info = xbt_dynar_get_as(privateLinks_, src->id(), s_surf_parsing_link_up_down_t);
106
107       if (info.link_up) {     // link up
108
109         const char *link_name = static_cast<simgrid::surf::Resource*>(
110           info.link_up)->getName();
111         current = new_xbt_graph_node(graph, link_name, nodes);
112         new_xbt_graph_edge(graph, previous, current, edges);
113
114         if (backbone_) {
115           new_xbt_graph_edge(graph, current, backboneNode, edges);
116         } else {
117           new_xbt_graph_edge(graph, current, routerNode, edges);
118         }
119
120       }
121
122       if (info.link_down) {    // link down
123         const char *link_name = static_cast<simgrid::surf::Resource*>(
124           info.link_down)->getName();
125         current = new_xbt_graph_node(graph, link_name, nodes);
126         new_xbt_graph_edge(graph, previous, current, edges);
127
128         if (backbone_) {
129           new_xbt_graph_edge(graph, current, backboneNode, edges);
130         } else {
131           new_xbt_graph_edge(graph, current, routerNode, edges);
132         }
133       }
134     }
135
136   }
137 }
138
139 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
140   s_surf_parsing_link_up_down_t info;
141   char* link_id = bprintf("%s_link_%d", cluster->id, id);
142
143   s_sg_platf_link_cbarg_t link;
144   memset(&link, 0, sizeof(link));
145   link.id = link_id;
146   link.bandwidth = cluster->bw;
147   link.latency = cluster->lat;
148   link.policy = cluster->sharing_policy;
149   sg_platf_new_link(&link);
150
151   if (link.policy == SURF_LINK_FULLDUPLEX) {
152     char *tmp_link = bprintf("%s_UP", link_id);
153     info.link_up = Link::byName(tmp_link);
154     xbt_free(tmp_link);
155     tmp_link = bprintf("%s_DOWN", link_id);
156     info.link_down = Link::byName(tmp_link);
157     xbt_free(tmp_link);
158   } else {
159     info.link_up = info.link_down = Link::byName(link_id);
160   }
161   xbt_dynar_set(privateLinks_, position, &info);
162   xbt_free(link_id);
163 }
164
165 }
166 }