Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add limiter_link option to cluster tag, to add a pseudo-shared link, to limit bandwid...
[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_VERB("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.limiter_link)          // limiter for sender
34       xbt_dynar_push_as(route->link_list, void *, info.limiter_link);
35     
36     if (info.link_up) {         // link up
37       xbt_dynar_push_as(route->link_list, void *, info.link_up);
38       if (lat)
39         *lat +=
40             surf_network_model->extension.network.get_link_latency(info.
41                                                                    link_up);
42     }
43   }
44
45   if (((as_cluster_t) as)->backbone) {
46     xbt_dynar_push_as(route->link_list, void *, ((as_cluster_t) as)->backbone);
47     if (lat)
48       *lat +=
49           surf_network_model->extension.network.
50           get_link_latency(((as_cluster_t) as)->backbone);
51   }
52
53   if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
54     info =
55         xbt_dynar_get_as(as->link_up_down_list, dst->id,
56                          s_surf_parsing_link_up_down_t);
57     if (info.link_down) {       // link down
58       xbt_dynar_push_as(route->link_list, void *, info.link_down);
59       if (lat)
60         *lat +=
61             surf_network_model->extension.network.get_link_latency(info.
62                                                                    link_down);
63     }
64     
65     if (info.limiter_link)          // limiter for receiver
66       xbt_dynar_push_as(route->link_list, void *, info.limiter_link);
67     
68   }
69 }
70
71 static void cluster_get_graph(xbt_graph_t graph, xbt_dict_t nodes,
72                               xbt_dict_t edges, AS_t rc)
73 {
74   int isrc;
75   int table_size = xbt_dynar_length(rc->index_network_elm);
76
77   sg_routing_edge_t src;
78   xbt_node_t current, previous, backboneNode = NULL, routerNode;
79   s_surf_parsing_link_up_down_t info;
80
81   xbt_assert(((as_cluster_t) rc)->router,"Malformed cluster");
82
83   /* create the router */
84   char *link_name =
85     ((sg_routing_edge_t) ((as_cluster_t) rc)->router)->name;
86   routerNode = new_xbt_graph_node(graph, link_name, nodes);
87
88   if(((as_cluster_t) rc)->backbone) {
89     char *link_nameR =
90       ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
91     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
92
93     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
94   }
95
96   for (isrc = 0; isrc < table_size; isrc++) {
97     src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t);
98
99     if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {
100       previous = new_xbt_graph_node(graph, src->name, nodes);
101
102       info = xbt_dynar_get_as(rc->link_up_down_list, src->id,
103                               s_surf_parsing_link_up_down_t);
104
105       if (info.link_up) {     // link up
106
107         char *link_name = ((surf_resource_t) info.link_up)->name;
108         current = new_xbt_graph_node(graph, link_name, nodes);
109         new_xbt_graph_edge(graph, previous, current, edges);
110
111         if (((as_cluster_t) rc)->backbone) {
112           new_xbt_graph_edge(graph, current, backboneNode, edges);
113         } else {
114           new_xbt_graph_edge(graph, current, routerNode, edges);
115         }
116
117       }
118
119       if (info.link_down) {    // link down
120         char *link_name = ((surf_resource_t) info.link_down)->name;
121         current = new_xbt_graph_node(graph, link_name, nodes);
122         new_xbt_graph_edge(graph, previous, current, edges);
123
124         if (((as_cluster_t) rc)->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 static void model_cluster_finalize(AS_t as)
136 {
137   model_none_finalize(as);
138 }
139
140 static int cluster_parse_PU(AS_t rc, sg_routing_edge_t elm) {
141   XBT_DEBUG("Load process unit \"%s\"", elm->name);
142   xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
143   return xbt_dynar_length(rc->index_network_elm)-1;
144 }
145
146 static int cluster_parse_AS(AS_t rc, sg_routing_edge_t elm) {
147   XBT_DEBUG("Load Autonomous system \"%s\"", elm->name);
148   xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
149   return xbt_dynar_length(rc->index_network_elm)-1;
150 }
151
152 /* Creation routing model functions */
153 AS_t model_cluster_create(void)
154 {
155   AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
156   result->get_route_and_latency = cluster_get_route_and_latency;
157   result->finalize = model_cluster_finalize;
158   result->get_graph = cluster_get_graph;
159   result->parse_AS = cluster_parse_AS;
160   result->parse_PU = cluster_parse_PU;
161
162   return (AS_t) result;
163 }