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 /* Business methods */
25 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
27 s_surf_parsing_link_up_down_t info;
28 XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
29 src->getName(), src->getId(), dst->getName(), dst->getId());
31 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
33 if((src->getId() == dst->getId()) && p_has_loopback ){
34 info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
35 xbt_dynar_push_as(route->link_list, void *, info.link_up);
37 *lat += static_cast<Link*>(info.link_up)->getLatency();
42 if (p_has_limiter){ // limiter for sender
43 info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
44 xbt_dynar_push_as(route->link_list, void *, info.link_up);
47 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);
48 if (info.link_up) { // link up
49 xbt_dynar_push_as(route->link_list, void *, info.link_up);
51 *lat += static_cast<Link*>(info.link_up)->getLatency();
57 xbt_dynar_push_as(route->link_list, void *,
58 static_cast<simgrid::surf::Resource*>(p_backbone));
60 *lat += p_backbone->getLatency();
63 if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
64 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);
66 if (info.link_down) { // link down
67 xbt_dynar_push_as(route->link_list, void *, info.link_down);
69 *lat += static_cast<Link*>(info.link_down)->getLatency();
71 if (p_has_limiter){ // limiter for receiver
72 info = xbt_dynar_get_as(p_linkUpDownList, dst->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
73 xbt_dynar_push_as(route->link_list, void *, info.link_up);
78 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
81 int table_size = xbt_dynar_length(p_indexNetworkElm);
84 xbt_node_t current, previous, backboneNode = NULL, routerNode;
85 s_surf_parsing_link_up_down_t info;
87 xbt_assert(p_router,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
89 /* create the router */
90 char *link_name = p_router->getName();
91 routerNode = new_xbt_graph_node(graph, link_name, nodes);
94 const char *link_nameR = p_backbone->getName();
95 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
97 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
100 for (isrc = 0; isrc < table_size; isrc++) {
101 src = xbt_dynar_get_as(p_indexNetworkElm, isrc, NetCard*);
103 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
104 previous = new_xbt_graph_node(graph, src->getName(), nodes);
106 info = xbt_dynar_get_as(p_linkUpDownList, src->getId(), s_surf_parsing_link_up_down_t);
108 if (info.link_up) { // link up
110 const char *link_name = static_cast<simgrid::surf::Resource*>(
111 info.link_up)->getName();
112 current = new_xbt_graph_node(graph, link_name, nodes);
113 new_xbt_graph_edge(graph, previous, current, edges);
116 new_xbt_graph_edge(graph, current, backboneNode, edges);
118 new_xbt_graph_edge(graph, current, routerNode, edges);
123 if (info.link_down) { // link down
124 const char *link_name = static_cast<simgrid::surf::Resource*>(
125 info.link_down)->getName();
126 current = new_xbt_graph_node(graph, link_name, nodes);
127 new_xbt_graph_edge(graph, previous, current, edges);
130 new_xbt_graph_edge(graph, current, backboneNode, edges);
132 new_xbt_graph_edge(graph, current, routerNode, edges);
140 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
141 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
142 s_surf_parsing_link_up_down_t info;
143 char* link_id = bprintf("%s_link_%d", cluster->id, id);
145 memset(&link, 0, sizeof(link));
147 link.bandwidth = cluster->bw;
148 link.latency = cluster->lat;
149 link.initiallyOn = 1;
150 link.policy = cluster->sharing_policy;
151 sg_platf_new_link(&link);
153 if (link.policy == SURF_LINK_FULLDUPLEX) {
154 char *tmp_link = bprintf("%s_UP", link_id);
155 info.link_up = sg_link_by_name(tmp_link);
157 tmp_link = bprintf("%s_DOWN", link_id);
158 info.link_down = sg_link_by_name(tmp_link);
161 info.link_up = sg_link_by_name(link_id);
162 info.link_down = info.link_up;
164 xbt_dynar_set(p_linkUpDownList, position, &info);
168 int AsCluster::parsePU(NetCard *elm) {
169 XBT_DEBUG("Load process unit \"%s\"", elm->getName());
170 xbt_dynar_push_as(p_indexNetworkElm, NetCard*, elm);
171 return xbt_dynar_length(p_indexNetworkElm)-1;
174 int AsCluster::parseAS(NetCard *elm) {
175 XBT_DEBUG("Load Autonomous system \"%s\"", elm->getName());
176 xbt_dynar_push_as(p_indexNetworkElm, NetCard*, elm);
177 return xbt_dynar_length(p_indexNetworkElm)-1;