1 /* Copyright (c) 2009-2011, 2013-2015. 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. */
7 #include "surf_routing_cluster.hpp"
8 #include "surf_routing_private.hpp"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
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.
16 AS_t model_cluster_create(void)
18 return new simgrid::surf::AsCluster();
24 /* Creation routing model functions */
25 AsCluster::AsCluster() : AsNone()
32 p_nb_links_per_node = 1;
35 /* Business methods */
36 void AsCluster::getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_route_cbarg_t route, double *lat)
38 s_surf_parsing_link_up_down_t info;
39 XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
40 src->getName(), src->getId(), dst->getName(), dst->getId());
42 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
44 if((src->getId() == dst->getId()) && p_has_loopback ){
45 info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
46 xbt_dynar_push_as(route->link_list, void *, info.link_up);
48 *lat += static_cast<Link*>(info.link_up)->getLatency();
53 if (p_has_limiter){ // limiter for sender
54 info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
55 xbt_dynar_push_as(route->link_list, void *, info.link_up);
58 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);
59 if (info.link_up) { // link up
60 xbt_dynar_push_as(route->link_list, void *, info.link_up);
62 *lat += static_cast<Link*>(info.link_up)->getLatency();
68 xbt_dynar_push_as(route->link_list, void *,
69 static_cast<simgrid::surf::Resource*>(p_backbone));
71 *lat += p_backbone->getLatency();
74 if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
75 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);
77 if (info.link_down) { // link down
78 xbt_dynar_push_as(route->link_list, void *, info.link_down);
80 *lat += static_cast<Link*>(info.link_down)->getLatency();
82 if (p_has_limiter){ // limiter for receiver
83 info = xbt_dynar_get_as(p_linkUpDownList, dst->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
84 xbt_dynar_push_as(route->link_list, void *, info.link_up);
89 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
92 int table_size = xbt_dynar_length(p_indexNetworkElm);
95 xbt_node_t current, previous, backboneNode = NULL, routerNode;
96 s_surf_parsing_link_up_down_t info;
98 xbt_assert(p_router,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
100 /* create the router */
101 char *link_name = p_router->getName();
102 routerNode = new_xbt_graph_node(graph, link_name, nodes);
105 const char *link_nameR = p_backbone->getName();
106 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
108 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
111 for (isrc = 0; isrc < table_size; isrc++) {
112 src = xbt_dynar_get_as(p_indexNetworkElm, isrc, RoutingEdge*);
114 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
115 previous = new_xbt_graph_node(graph, src->getName(), nodes);
117 info = xbt_dynar_get_as(p_linkUpDownList, src->getId(), s_surf_parsing_link_up_down_t);
119 if (info.link_up) { // link up
121 const char *link_name = static_cast<simgrid::surf::Resource*>(
122 info.link_up)->getName();
123 current = new_xbt_graph_node(graph, link_name, nodes);
124 new_xbt_graph_edge(graph, previous, current, edges);
127 new_xbt_graph_edge(graph, current, backboneNode, edges);
129 new_xbt_graph_edge(graph, current, routerNode, edges);
134 if (info.link_down) { // link down
135 const char *link_name = static_cast<simgrid::surf::Resource*>(
136 info.link_down)->getName();
137 current = new_xbt_graph_node(graph, link_name, nodes);
138 new_xbt_graph_edge(graph, previous, current, edges);
141 new_xbt_graph_edge(graph, current, backboneNode, edges);
143 new_xbt_graph_edge(graph, current, routerNode, edges);
151 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
152 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
153 s_surf_parsing_link_up_down_t info;
154 char* link_id = bprintf("%s_link_%d", cluster->id, id);
156 memset(&link, 0, sizeof(link));
158 link.bandwidth = cluster->bw;
159 link.latency = cluster->lat;
160 link.state = SURF_RESOURCE_ON;
161 link.policy = cluster->sharing_policy;
162 sg_platf_new_link(&link);
164 if (link.policy == SURF_LINK_FULLDUPLEX) {
165 char *tmp_link = bprintf("%s_UP", link_id);
166 info.link_up = sg_link_by_name(tmp_link);
168 tmp_link = bprintf("%s_DOWN", link_id);
169 info.link_down = sg_link_by_name(tmp_link);
172 info.link_up = sg_link_by_name(link_id);
173 info.link_down = info.link_up;
175 xbt_dynar_set(p_linkUpDownList, position, &info);
179 int AsCluster::parsePU(RoutingEdge *elm) {
180 XBT_DEBUG("Load process unit \"%s\"", elm->getName());
181 xbt_dynar_push_as(p_indexNetworkElm, RoutingEdge*, elm);
182 return xbt_dynar_length(p_indexNetworkElm)-1;
185 int AsCluster::parseAS(RoutingEdge *elm) {
186 XBT_DEBUG("Load Autonomous system \"%s\"", elm->getName());
187 xbt_dynar_push_as(p_indexNetworkElm, RoutingEdge*, elm);
188 return xbt_dynar_length(p_indexNetworkElm)-1;