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.
18 AsCluster::AsCluster(const char*name)
22 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
24 s_surf_parsing_link_up_down_t info;
25 XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
26 src->name(), src->id(), dst->name(), dst->id());
28 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
30 if((src->id() == dst->id()) && has_loopback_ ){
31 info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_, s_surf_parsing_link_up_down_t);
32 xbt_dynar_push_as(route->link_list, void *, info.link_up);
34 *lat += static_cast<Link*>(info.link_up)->getLatency();
39 if (has_limiter_){ // limiter for sender
40 info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
41 xbt_dynar_push_as(route->link_list, void *, info.link_up);
44 info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
45 if (info.link_up) { // link up
46 xbt_dynar_push_as(route->link_list, void *, info.link_up);
48 *lat += static_cast<Link*>(info.link_up)->getLatency();
54 xbt_dynar_push_as(route->link_list, void *,
55 static_cast<simgrid::surf::Resource*>(backbone_));
57 *lat += backbone_->getLatency();
60 if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
61 info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
63 if (info.link_down) { // link down
64 xbt_dynar_push_as(route->link_list, void *, info.link_down);
66 *lat += static_cast<Link*>(info.link_down)->getLatency();
68 if (has_limiter_){ // limiter for receiver
69 info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
70 xbt_dynar_push_as(route->link_list, void *, info.link_up);
75 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
78 int table_size = xbt_dynar_length(vertices_);
81 xbt_node_t current, previous, backboneNode = NULL, routerNode;
82 s_surf_parsing_link_up_down_t info;
84 xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
86 /* create the router */
87 char *link_name = router_->name();
88 routerNode = new_xbt_graph_node(graph, link_name, nodes);
91 const char *link_nameR = backbone_->getName();
92 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
94 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
97 for (isrc = 0; isrc < table_size; isrc++) {
98 src = xbt_dynar_get_as(vertices_, isrc, NetCard*);
100 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
101 previous = new_xbt_graph_node(graph, src->name(), nodes);
103 info = xbt_dynar_get_as(upDownLinks, src->id(), s_surf_parsing_link_up_down_t);
105 if (info.link_up) { // link up
107 const char *link_name = static_cast<simgrid::surf::Resource*>(
108 info.link_up)->getName();
109 current = new_xbt_graph_node(graph, link_name, nodes);
110 new_xbt_graph_edge(graph, previous, current, edges);
113 new_xbt_graph_edge(graph, current, backboneNode, edges);
115 new_xbt_graph_edge(graph, current, routerNode, edges);
120 if (info.link_down) { // link down
121 const char *link_name = static_cast<simgrid::surf::Resource*>(
122 info.link_down)->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);
137 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
138 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
139 s_surf_parsing_link_up_down_t info;
140 char* link_id = bprintf("%s_link_%d", cluster->id, id);
142 memset(&link, 0, sizeof(link));
144 link.bandwidth = cluster->bw;
145 link.latency = cluster->lat;
146 link.initiallyOn = 1;
147 link.policy = cluster->sharing_policy;
148 sg_platf_new_link(&link);
150 if (link.policy == SURF_LINK_FULLDUPLEX) {
151 char *tmp_link = bprintf("%s_UP", link_id);
152 info.link_up = sg_link_by_name(tmp_link);
154 tmp_link = bprintf("%s_DOWN", link_id);
155 info.link_down = sg_link_by_name(tmp_link);
158 info.link_up = sg_link_by_name(link_id);
159 info.link_down = info.link_up;
161 xbt_dynar_set(upDownLinks, position, &info);