Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[travis] detect linux as we should
[simgrid.git] / src / surf / surf_routing_cluster.cpp
1 /* Copyright (c) 2009-2011, 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "surf_routing_cluster.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 AS_t model_cluster_create(void)
16 {
17   return new AsCluster();
18 }
19
20 /* Creation routing model functions */
21 AsCluster::AsCluster() : AsNone()
22 {
23   p_backbone = 0;
24   p_loopback = 0;
25   p_router = 0;
26   p_has_limiter = 0;
27   p_has_loopback = 0;
28   p_nb_links_per_node = 1;
29 }
30
31 /* Business methods */
32 void AsCluster::getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_route_cbarg_t route, double *lat)
33 {
34   s_surf_parsing_link_up_down_t info;
35   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
36             src->getName(), src->getId(), dst->getName(), dst->getId());
37
38   if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
39
40     if((src->getId() == dst->getId()) && p_has_loopback  ){
41       info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
42       xbt_dynar_push_as(route->link_list, void *, info.link_up);
43       if (lat)
44         *lat += static_cast<Link*>(info.link_up)->getLatency();
45       return;
46     }
47
48
49     if (p_has_limiter){          // limiter for sender
50       info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
51       xbt_dynar_push_as(route->link_list, void *, info.link_up);
52     }
53
54     info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
55     if (info.link_up) {         // link up
56       xbt_dynar_push_as(route->link_list, void *, info.link_up);
57       if (lat)
58         *lat += static_cast<Link*>(info.link_up)->getLatency();
59     }
60
61   }
62
63   if (p_backbone) {
64     xbt_dynar_push_as(route->link_list, void *, static_cast<Resource*>(p_backbone));
65     if (lat)
66       *lat += p_backbone->getLatency();
67   }
68
69   if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
70     info = xbt_dynar_get_as(p_linkUpDownList, dst->getId() * p_nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
71
72     if (info.link_down) {       // link down
73       xbt_dynar_push_as(route->link_list, void *, info.link_down);
74       if (lat)
75         *lat += static_cast<Link*>(info.link_down)->getLatency();
76     }
77     if (p_has_limiter){          // limiter for receiver
78         info = xbt_dynar_get_as(p_linkUpDownList, dst->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
79         xbt_dynar_push_as(route->link_list, void *, info.link_up);
80     }
81   }
82 }
83
84 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
85 {
86   int isrc;
87   int table_size = xbt_dynar_length(p_indexNetworkElm);
88
89   RoutingEdge *src;
90   xbt_node_t current, previous, backboneNode = NULL, routerNode;
91   s_surf_parsing_link_up_down_t info;
92
93   xbt_assert(p_router,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
94
95   /* create the router */
96   char *link_name = p_router->getName();
97   routerNode = new_xbt_graph_node(graph, link_name, nodes);
98
99   if(p_backbone) {
100     const char *link_nameR = p_backbone->getName();
101     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
102
103     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
104   }
105
106   for (isrc = 0; isrc < table_size; isrc++) {
107     src = xbt_dynar_get_as(p_indexNetworkElm, isrc, RoutingEdge*);
108
109     if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
110       previous = new_xbt_graph_node(graph, src->getName(), nodes);
111
112       info = xbt_dynar_get_as(p_linkUpDownList, src->getId(), s_surf_parsing_link_up_down_t);
113
114       if (info.link_up) {     // link up
115
116         const char *link_name = static_cast<Resource*>(info.link_up)->getName();
117         current = new_xbt_graph_node(graph, link_name, nodes);
118         new_xbt_graph_edge(graph, previous, current, edges);
119
120         if (p_backbone) {
121           new_xbt_graph_edge(graph, current, backboneNode, edges);
122         } else {
123           new_xbt_graph_edge(graph, current, routerNode, edges);
124         }
125
126       }
127
128       if (info.link_down) {    // link down
129         const char *link_name = static_cast<Resource*>(info.link_down)->getName();
130         current = new_xbt_graph_node(graph, link_name, nodes);
131         new_xbt_graph_edge(graph, previous, current, edges);
132
133         if (p_backbone) {
134           new_xbt_graph_edge(graph, current, backboneNode, edges);
135         } else {
136           new_xbt_graph_edge(graph, current, routerNode, edges);
137         }
138       }
139     }
140
141   }
142 }
143
144 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
145   s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
146   s_surf_parsing_link_up_down_t info;
147   char* link_id = bprintf("%s_link_%d", cluster->id, id);
148
149   memset(&link, 0, sizeof(link));
150   link.id = link_id;
151   link.bandwidth = cluster->bw;
152   link.latency = cluster->lat;
153   link.state = SURF_RESOURCE_ON;
154   link.policy = cluster->sharing_policy;
155   sg_platf_new_link(&link);
156
157   if (link.policy == SURF_LINK_FULLDUPLEX) {
158     char *tmp_link = bprintf("%s_UP", link_id);
159     info.link_up = sg_link_by_name(tmp_link);
160     xbt_free(tmp_link);
161     tmp_link = bprintf("%s_DOWN", link_id);
162     info.link_down = sg_link_by_name(tmp_link);
163     xbt_free(tmp_link);
164   } else {
165     info.link_up = sg_link_by_name(link_id);
166     info.link_down = info.link_up;
167   }
168   xbt_dynar_set(p_linkUpDownList, position, &info);
169   xbt_free(link_id);
170 }
171
172 int AsCluster::parsePU(RoutingEdge *elm) {
173   XBT_DEBUG("Load process unit \"%s\"", elm->getName());
174   xbt_dynar_push_as(p_indexNetworkElm, RoutingEdge*, elm);
175   return xbt_dynar_length(p_indexNetworkElm)-1;
176 }
177
178 int AsCluster::parseAS(RoutingEdge *elm) {
179   XBT_DEBUG("Load Autonomous system \"%s\"", elm->getName());
180   xbt_dynar_push_as(p_indexNetworkElm, RoutingEdge*, elm);
181   return xbt_dynar_length(p_indexNetworkElm)-1;
182 }
183