Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add missing declaration.
[simgrid.git] / src / surf / surf_routing_cluster.c
1 /* Copyright (c) 2009, 2010, 2011. 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 #include "surf_routing_private.h"
7 #include "xbt/graph.h"
8
9 /* Global vars */
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
17 /* Business methods */
18 static void cluster_get_route_and_latency(AS_t as,
19                                           sg_routing_edge_t src,
20                                           sg_routing_edge_t dst,
21                                           sg_platf_route_cbarg_t route,
22                                           double *lat)
23 {
24
25   s_surf_parsing_link_up_down_t info;
26   XBT_DEBUG("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
27             src->name, src->id, dst->name, dst->id);
28
29   if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
30     info =
31         xbt_dynar_get_as(as->link_up_down_list, src->id,
32                          s_surf_parsing_link_up_down_t);
33     if (info.link_up) {         // link up
34       xbt_dynar_push_as(route->link_list, void *, info.link_up);
35       if (lat)
36         *lat +=
37             surf_network_model->extension.network.get_link_latency(info.
38                                                                    link_up);
39     }
40   }
41
42   if (((as_cluster_t) as)->backbone) {
43     xbt_dynar_push_as(route->link_list, void *, ((as_cluster_t) as)->backbone);
44     if (lat)
45       *lat +=
46           surf_network_model->extension.network.
47           get_link_latency(((as_cluster_t) as)->backbone);
48   }
49
50   if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
51     info =
52         xbt_dynar_get_as(as->link_up_down_list, dst->id,
53                          s_surf_parsing_link_up_down_t);
54     if (info.link_down) {       // link down
55       xbt_dynar_push_as(route->link_list, void *, info.link_down);
56       if (lat)
57         *lat +=
58             surf_network_model->extension.network.get_link_latency(info.
59                                                                    link_down);
60     }
61   }
62 }
63
64 static void cluster_get_graph(xbt_graph_t graph, xbt_dict_t nodes,
65                               xbt_dict_t edges, AS_t rc)
66 {
67   int isrc;
68   int table_size = xbt_dynar_length(rc->index_network_elm);
69
70   sg_routing_edge_t src, dst;
71   xbt_node_t current, previous, backboneNode,routerNode;
72   s_surf_parsing_link_up_down_t info;
73
74   xbt_assert(((as_cluster_t) rc)->router,"Malformed cluster");
75
76   /* create the router */
77   char *link_name =
78                   ((sg_routing_edge_t) ((as_cluster_t) rc)->router)->name;
79   routerNode = new_xbt_graph_node(graph, link_name, nodes);
80
81   if(((as_cluster_t) rc)->backbone) {
82           char *link_nameR =
83                           ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
84           backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
85
86           new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
87   }
88
89   for (isrc = 0; isrc < table_size; isrc++) {
90           src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t);
91
92           if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {
93                           previous = new_xbt_graph_node(graph, src->name, nodes);
94
95                           info = xbt_dynar_get_as(rc->link_up_down_list, src->id,
96                                           s_surf_parsing_link_up_down_t);
97
98                           if (info.link_up) {     // link up
99
100                                   char *link_name = ((surf_resource_t) info.link_up)->name;
101                                   current = new_xbt_graph_node(graph, link_name, nodes);
102                                   new_xbt_graph_edge(graph, previous, current, edges);
103
104                                   if (((as_cluster_t) rc)->backbone) {
105                                           new_xbt_graph_edge(graph, current, backboneNode, edges);
106                                   } else {
107                                           new_xbt_graph_edge(graph, current, routerNode, edges);
108                                   }
109
110                           }
111
112                           if (info.link_down) {    // link down
113                                   char *link_name = ((surf_resource_t) info.link_down)->name;
114                                   current = new_xbt_graph_node(graph, link_name, nodes);
115                                   new_xbt_graph_edge(graph, previous, current, edges);
116
117                                   if (((as_cluster_t) rc)->backbone) {
118                                           new_xbt_graph_edge(graph, current, backboneNode, edges);
119                                   } else {
120                                           new_xbt_graph_edge(graph, current, routerNode, edges);
121                                   }
122
123                           }
124                   }
125   }
126
127 /*
128                   if (((as_cluster_t) rc)->backbone) {
129                           char *link_name =
130                                           ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
131
132                           current = new_xbt_graph_node(graph, link_name, nodes);
133                           new_xbt_graph_edge(graph, previous, current, edges);
134                           previous = current;
135
136                           revCurrent = new_xbt_graph_node(graph, link_name, nodes);
137                           new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
138                           revPrevious = revCurrent;
139                   } else {
140                           info = xbt_dynar_get_as(rc->link_up_down_list, dst->id,
141                                                                           s_surf_parsing_link_up_down_t);
142
143                           if (info.link_up) {     // link up
144                                   char *link_name = ((surf_resource_t) info.link_up)->name;
145                                   current = new_xbt_graph_node(graph, link_name, nodes);
146                                   new_xbt_graph_edge(graph, previous, current, edges);
147                                   previous = current;
148                           } else if (info.link_down) {    // link down
149                                   char *link_name = ((surf_resource_t) info.link_down)->name;
150                                   revCurrent = new_xbt_graph_node(graph, link_name, nodes);
151                                   new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
152                                   revPrevious = revCurrent;
153                           }
154                   }
155
156           }
157   }*/
158 /*
159   if(rc->)
160   for (isrc = 0; isrc < table_size; isrc++) {
161     src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t);
162
163     previous = new_xbt_graph_node(graph, src->name, nodes);
164     revPrevious = new_xbt_graph_node(graph, src->name, nodes);
165
166     for (idst = isrc + 1; idst < table_size; idst++) {
167       dst = xbt_dynar_get_as(rc->index_network_elm, idst, sg_routing_edge_t);
168
169       s_surf_parsing_link_up_down_t info;
170
171       if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {        // No specific link for router
172         info =
173             xbt_dynar_get_as(rc->link_up_down_list, src->id,
174                              s_surf_parsing_link_up_down_t);
175
176         if (info.link_up) {     // link up
177           char *link_name = ((surf_resource_t) info.link_up)->name;
178           current = new_xbt_graph_node(graph, link_name, nodes);
179           new_xbt_graph_edge(graph, previous, current, edges);
180           previous = current;
181         } else if (info.link_down) {    // link down
182           char *link_name = ((surf_resource_t) info.link_down)->name;
183           revCurrent = new_xbt_graph_node(graph, link_name, nodes);
184           new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
185           revPrevious = revCurrent;
186         }
187       }
188
189
190
191       if (((as_cluster_t) rc)->backbone) {
192         char *link_name =
193             ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
194
195         current = new_xbt_graph_node(graph, link_name, nodes);
196         new_xbt_graph_edge(graph, previous, current, edges);
197         previous = current;
198
199         revCurrent = new_xbt_graph_node(graph, link_name, nodes);
200         new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
201         revPrevious = revCurrent;
202       }
203
204       if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {        // No specific link for router
205         info =
206             xbt_dynar_get_as(rc->link_up_down_list, dst->id,
207                              s_surf_parsing_link_up_down_t);
208
209         if (info.link_up) {     // link up
210           char *link_name = ((surf_resource_t) info.link_up)->name;
211           current = new_xbt_graph_node(graph, link_name, nodes);
212           new_xbt_graph_edge(graph, previous, current, edges);
213           previous = current;
214         } else if (info.link_down) {    // link down
215           char *link_name = ((surf_resource_t) info.link_down)->name;
216           revCurrent = new_xbt_graph_node(graph, link_name, nodes);
217           new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
218           revPrevious = revCurrent;
219         }
220       }
221
222     }
223   }*/
224 }
225
226 static void model_cluster_finalize(AS_t as)
227 {
228   model_none_finalize(as);
229 }
230
231 static int cluster_parse_PU(AS_t rc, sg_routing_edge_t elm) {
232   XBT_DEBUG("Load process unit \"%s\"", elm->name);
233   xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
234   return xbt_dynar_length(rc->index_network_elm)-1;
235 }
236
237 static int cluster_parse_AS(AS_t rc, sg_routing_edge_t elm) {
238   XBT_DEBUG("Load Autonomous system \"%s\"", elm->name);
239   xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
240   return xbt_dynar_length(rc->index_network_elm)-1;
241 }
242
243 /* Creation routing model functions */
244 AS_t model_cluster_create(void)
245 {
246   AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
247   result->get_route_and_latency = cluster_get_route_and_latency;
248   result->finalize = model_cluster_finalize;
249   result->get_graph = cluster_get_graph;
250   result->parse_AS = cluster_parse_AS;
251   result->parse_PU = cluster_parse_PU;
252
253   return (AS_t) result;
254 }