1 /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
2 * All rights reserved. */
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"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
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.
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,
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);
29 if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
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);
37 surf_network_model->extension.network.get_link_latency(info.
42 if (((as_cluster_t) as)->backbone) {
43 xbt_dynar_push_as(route->link_list, void *, ((as_cluster_t) as)->backbone);
46 surf_network_model->extension.network.
47 get_link_latency(((as_cluster_t) as)->backbone);
50 if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
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);
58 surf_network_model->extension.network.get_link_latency(info.
64 static void cluster_get_graph(xbt_graph_t graph, xbt_dict_t nodes,
65 xbt_dict_t edges, AS_t rc)
68 int table_size = xbt_dynar_length(rc->index_network_elm);
70 sg_routing_edge_t src;
71 xbt_node_t current, previous, backboneNode,routerNode;
72 s_surf_parsing_link_up_down_t info;
74 xbt_assert(((as_cluster_t) rc)->router,"Malformed cluster");
76 /* create the router */
78 ((sg_routing_edge_t) ((as_cluster_t) rc)->router)->name;
79 routerNode = new_xbt_graph_node(graph, link_name, nodes);
81 if(((as_cluster_t) rc)->backbone) {
83 ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
84 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
86 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
89 for (isrc = 0; isrc < table_size; isrc++) {
90 src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t);
92 if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {
93 previous = new_xbt_graph_node(graph, src->name, nodes);
95 info = xbt_dynar_get_as(rc->link_up_down_list, src->id,
96 s_surf_parsing_link_up_down_t);
98 if (info.link_up) { // link up
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);
104 if (((as_cluster_t) rc)->backbone) {
105 new_xbt_graph_edge(graph, current, backboneNode, edges);
107 new_xbt_graph_edge(graph, current, routerNode, edges);
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);
117 if (((as_cluster_t) rc)->backbone) {
118 new_xbt_graph_edge(graph, current, backboneNode, edges);
120 new_xbt_graph_edge(graph, current, routerNode, edges);
125 if (((as_cluster_t) rc)->backbone) {
127 ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
129 current = new_xbt_graph_node(graph, link_name, nodes);
130 new_xbt_graph_edge(graph, previous, current, edges);
133 revCurrent = new_xbt_graph_node(graph, link_name, nodes);
134 new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
135 revPrevious = revCurrent;
137 info = xbt_dynar_get_as(rc->link_up_down_list, dst->id,
138 s_surf_parsing_link_up_down_t);
140 if (info.link_up) { // link up
141 char *link_name = ((surf_resource_t) info.link_up)->name;
142 current = new_xbt_graph_node(graph, link_name, nodes);
143 new_xbt_graph_edge(graph, previous, current, edges);
145 } else if (info.link_down) { // link down
146 char *link_name = ((surf_resource_t) info.link_down)->name;
147 revCurrent = new_xbt_graph_node(graph, link_name, nodes);
148 new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
149 revPrevious = revCurrent;
157 for (isrc = 0; isrc < table_size; isrc++) {
158 src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t);
160 previous = new_xbt_graph_node(graph, src->name, nodes);
161 revPrevious = new_xbt_graph_node(graph, src->name, nodes);
163 for (idst = isrc + 1; idst < table_size; idst++) {
164 dst = xbt_dynar_get_as(rc->index_network_elm, idst, sg_routing_edge_t);
166 s_surf_parsing_link_up_down_t info;
168 if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
170 xbt_dynar_get_as(rc->link_up_down_list, src->id,
171 s_surf_parsing_link_up_down_t);
173 if (info.link_up) { // link up
174 char *link_name = ((surf_resource_t) info.link_up)->name;
175 current = new_xbt_graph_node(graph, link_name, nodes);
176 new_xbt_graph_edge(graph, previous, current, edges);
178 } else if (info.link_down) { // link down
179 char *link_name = ((surf_resource_t) info.link_down)->name;
180 revCurrent = new_xbt_graph_node(graph, link_name, nodes);
181 new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
182 revPrevious = revCurrent;
188 if (((as_cluster_t) rc)->backbone) {
190 ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
192 current = new_xbt_graph_node(graph, link_name, nodes);
193 new_xbt_graph_edge(graph, previous, current, edges);
196 revCurrent = new_xbt_graph_node(graph, link_name, nodes);
197 new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
198 revPrevious = revCurrent;
201 if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
203 xbt_dynar_get_as(rc->link_up_down_list, dst->id,
204 s_surf_parsing_link_up_down_t);
206 if (info.link_up) { // link up
207 char *link_name = ((surf_resource_t) info.link_up)->name;
208 current = new_xbt_graph_node(graph, link_name, nodes);
209 new_xbt_graph_edge(graph, previous, current, edges);
211 } else if (info.link_down) { // link down
212 char *link_name = ((surf_resource_t) info.link_down)->name;
213 revCurrent = new_xbt_graph_node(graph, link_name, nodes);
214 new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
215 revPrevious = revCurrent;
224 static void model_cluster_finalize(AS_t as)
226 model_none_finalize(as);
229 static int cluster_parse_PU(AS_t rc, sg_routing_edge_t elm) {
230 XBT_DEBUG("Load process unit \"%s\"", elm->name);
231 xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
232 return xbt_dynar_length(rc->index_network_elm)-1;
235 static int cluster_parse_AS(AS_t rc, sg_routing_edge_t elm) {
236 XBT_DEBUG("Load Autonomous system \"%s\"", elm->name);
237 xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
238 return xbt_dynar_length(rc->index_network_elm)-1;
241 /* Creation routing model functions */
242 AS_t model_cluster_create(void)
244 AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
245 result->get_route_and_latency = cluster_get_route_and_latency;
246 result->finalize = model_cluster_finalize;
247 result->get_graph = cluster_get_graph;
248 result->parse_AS = cluster_parse_AS;
249 result->parse_PU = cluster_parse_PU;
251 return (AS_t) result;