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, dst;
71 xbt_node_t current, previous, revCurrent, revPrevious;
73 for (isrc = 0; isrc < table_size; isrc++) {
74 src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t);
76 previous = new_xbt_graph_node(graph, src->name, nodes);
77 revPrevious = new_xbt_graph_node(graph, src->name, nodes);
79 for (idst = isrc + 1; idst < table_size; idst++) {
80 dst = xbt_dynar_get_as(rc->index_network_elm, idst, sg_routing_edge_t);
82 sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
83 route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
84 rc->get_route_and_latency(rc, src, dst, route, NULL);
86 s_surf_parsing_link_up_down_t info;
88 if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
90 xbt_dynar_get_as(rc->link_up_down_list, src->id,
91 s_surf_parsing_link_up_down_t);
93 if (info.link_up) { // link up
94 char *link_name = ((surf_resource_t) info.link_up)->name;
95 current = new_xbt_graph_node(graph, link_name, nodes);
96 new_xbt_graph_edge(graph, previous, current, edges);
98 } else if (info.link_down) { // link down
99 char *link_name = ((surf_resource_t) info.link_down)->name;
100 revCurrent = new_xbt_graph_node(graph, link_name, nodes);
101 new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
102 revPrevious = revCurrent;
106 if (((as_cluster_t) rc)->backbone) {
108 ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
110 current = new_xbt_graph_node(graph, link_name, nodes);
111 new_xbt_graph_edge(graph, previous, current, edges);
114 revCurrent = new_xbt_graph_node(graph, link_name, nodes);
115 new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
116 revPrevious = revCurrent;
119 if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
121 xbt_dynar_get_as(rc->link_up_down_list, dst->id,
122 s_surf_parsing_link_up_down_t);
124 if (info.link_up) { // link up
125 char *link_name = ((surf_resource_t) info.link_up)->name;
126 current = new_xbt_graph_node(graph, link_name, nodes);
127 new_xbt_graph_edge(graph, previous, current, edges);
129 } else if (info.link_down) { // link down
130 char *link_name = ((surf_resource_t) info.link_down)->name;
131 revCurrent = new_xbt_graph_node(graph, link_name, nodes);
132 new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
133 revPrevious = revCurrent;
141 static void model_cluster_finalize(AS_t as)
143 model_none_finalize(as);
146 static int cluster_parse_PU(AS_t rc, sg_routing_edge_t elm) {
147 XBT_DEBUG("Load process unit \"%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;
152 static int cluster_parse_AS(AS_t rc, sg_routing_edge_t elm) {
153 XBT_DEBUG("Load Autonomous system \"%s\"", elm->name);
154 xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
155 return xbt_dynar_length(rc->index_network_elm)-1;
158 /* Creation routing model functions */
159 AS_t model_cluster_create(void)
161 AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
162 result->get_route_and_latency = cluster_get_route_and_latency;
163 result->finalize = model_cluster_finalize;
164 result->get_graph = cluster_get_graph;
165 result->parse_AS = cluster_parse_AS;
166 result->parse_PU = cluster_parse_PU;
168 return (AS_t) result;