Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ebb2a58ebd0bccb6b0fe278762e797bf67fa8c5c
[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 #include "surf_routing_private.hpp"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
11
12 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
13  * Note that a router is created, easing the interconnexion with the rest of the world.
14  */
15
16 namespace simgrid {
17 namespace surf {
18
19 /* Business methods */
20 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
21 {
22   s_surf_parsing_link_up_down_t info;
23   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
24             src->getName(), src->getId(), dst->getName(), dst->getId());
25
26   if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
27
28     if((src->getId() == dst->getId()) && p_has_loopback  ){
29       info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
30       xbt_dynar_push_as(route->link_list, void *, info.link_up);
31       if (lat)
32         *lat += static_cast<Link*>(info.link_up)->getLatency();
33       return;
34     }
35
36
37     if (p_has_limiter){          // limiter for sender
38       info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
39       xbt_dynar_push_as(route->link_list, void *, info.link_up);
40     }
41
42     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);
43     if (info.link_up) {         // link up
44       xbt_dynar_push_as(route->link_list, void *, info.link_up);
45       if (lat)
46         *lat += static_cast<Link*>(info.link_up)->getLatency();
47     }
48
49   }
50
51   if (p_backbone) {
52     xbt_dynar_push_as(route->link_list, void *,
53       static_cast<simgrid::surf::Resource*>(p_backbone));
54     if (lat)
55       *lat += p_backbone->getLatency();
56   }
57
58   if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
59     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);
60
61     if (info.link_down) {       // link down
62       xbt_dynar_push_as(route->link_list, void *, info.link_down);
63       if (lat)
64         *lat += static_cast<Link*>(info.link_down)->getLatency();
65     }
66     if (p_has_limiter){          // limiter for receiver
67         info = xbt_dynar_get_as(p_linkUpDownList, dst->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
68         xbt_dynar_push_as(route->link_list, void *, info.link_up);
69     }
70   }
71 }
72
73 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
74 {
75   int isrc;
76   int table_size = xbt_dynar_length(p_indexNetworkElm);
77
78   NetCard *src;
79   xbt_node_t current, previous, backboneNode = NULL, routerNode;
80   s_surf_parsing_link_up_down_t info;
81
82   xbt_assert(p_router,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
83
84   /* create the router */
85   char *link_name = p_router->getName();
86   routerNode = new_xbt_graph_node(graph, link_name, nodes);
87
88   if(p_backbone) {
89     const char *link_nameR = p_backbone->getName();
90     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
91
92     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
93   }
94
95   for (isrc = 0; isrc < table_size; isrc++) {
96     src = xbt_dynar_get_as(p_indexNetworkElm, isrc, NetCard*);
97
98     if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
99       previous = new_xbt_graph_node(graph, src->getName(), nodes);
100
101       info = xbt_dynar_get_as(p_linkUpDownList, src->getId(), s_surf_parsing_link_up_down_t);
102
103       if (info.link_up) {     // link up
104
105         const char *link_name = static_cast<simgrid::surf::Resource*>(
106           info.link_up)->getName();
107         current = new_xbt_graph_node(graph, link_name, nodes);
108         new_xbt_graph_edge(graph, previous, current, edges);
109
110         if (p_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       if (info.link_down) {    // link down
119         const char *link_name = static_cast<simgrid::surf::Resource*>(
120           info.link_down)->getName();
121         current = new_xbt_graph_node(graph, link_name, nodes);
122         new_xbt_graph_edge(graph, previous, current, edges);
123
124         if (p_backbone) {
125           new_xbt_graph_edge(graph, current, backboneNode, edges);
126         } else {
127           new_xbt_graph_edge(graph, current, routerNode, edges);
128         }
129       }
130     }
131
132   }
133 }
134
135 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
136   s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
137   s_surf_parsing_link_up_down_t info;
138   char* link_id = bprintf("%s_link_%d", cluster->id, id);
139
140   memset(&link, 0, sizeof(link));
141   link.id = link_id;
142   link.bandwidth = cluster->bw;
143   link.latency = cluster->lat;
144   link.initiallyOn = 1;
145   link.policy = cluster->sharing_policy;
146   sg_platf_new_link(&link);
147
148   if (link.policy == SURF_LINK_FULLDUPLEX) {
149     char *tmp_link = bprintf("%s_UP", link_id);
150     info.link_up = sg_link_by_name(tmp_link);
151     xbt_free(tmp_link);
152     tmp_link = bprintf("%s_DOWN", link_id);
153     info.link_down = sg_link_by_name(tmp_link);
154     xbt_free(tmp_link);
155   } else {
156     info.link_up = sg_link_by_name(link_id);
157     info.link_down = info.link_up;
158   }
159   xbt_dynar_set(p_linkUpDownList, position, &info);
160   xbt_free(link_id);
161 }
162
163 int AsCluster::parsePU(NetCard *elm) {
164   XBT_DEBUG("Load process unit \"%s\"", elm->getName());
165   xbt_dynar_push_as(p_indexNetworkElm, NetCard*, elm);
166   return xbt_dynar_length(p_indexNetworkElm)-1;
167 }
168
169 int AsCluster::parseAS(NetCard *elm) {
170   XBT_DEBUG("Load Autonomous system \"%s\"", elm->getName());
171   xbt_dynar_push_as(p_indexNetworkElm, NetCard*, elm);
172   return xbt_dynar_length(p_indexNetworkElm)-1;
173 }
174
175 }
176 }