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.
19 /* Business methods */
20 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
22 s_surf_parsing_link_up_down_t info;
23 XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
24 src->getName(), src->getId(), dst->getName(), dst->getId());
26 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
28 if((src->getId() == dst->getId()) && p_has_loopback ){
29 info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
30 xbt_dynar_push_as(route->link_list, void *, info.link_up);
32 *lat += static_cast<Link*>(info.link_up)->getLatency();
37 if (p_has_limiter){ // limiter for sender
38 info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
39 xbt_dynar_push_as(route->link_list, void *, info.link_up);
42 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);
43 if (info.link_up) { // link up
44 xbt_dynar_push_as(route->link_list, void *, info.link_up);
46 *lat += static_cast<Link*>(info.link_up)->getLatency();
52 xbt_dynar_push_as(route->link_list, void *,
53 static_cast<simgrid::surf::Resource*>(p_backbone));
55 *lat += p_backbone->getLatency();
58 if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
59 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);
61 if (info.link_down) { // link down
62 xbt_dynar_push_as(route->link_list, void *, info.link_down);
64 *lat += static_cast<Link*>(info.link_down)->getLatency();
66 if (p_has_limiter){ // limiter for receiver
67 info = xbt_dynar_get_as(p_linkUpDownList, dst->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
68 xbt_dynar_push_as(route->link_list, void *, info.link_up);
73 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
76 int table_size = xbt_dynar_length(p_indexNetworkElm);
79 xbt_node_t current, previous, backboneNode = NULL, routerNode;
80 s_surf_parsing_link_up_down_t info;
82 xbt_assert(p_router,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
84 /* create the router */
85 char *link_name = p_router->getName();
86 routerNode = new_xbt_graph_node(graph, link_name, nodes);
89 const char *link_nameR = p_backbone->getName();
90 backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
92 new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
95 for (isrc = 0; isrc < table_size; isrc++) {
96 src = xbt_dynar_get_as(p_indexNetworkElm, isrc, NetCard*);
98 if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
99 previous = new_xbt_graph_node(graph, src->getName(), nodes);
101 info = xbt_dynar_get_as(p_linkUpDownList, src->getId(), s_surf_parsing_link_up_down_t);
103 if (info.link_up) { // link up
105 const char *link_name = static_cast<simgrid::surf::Resource*>(
106 info.link_up)->getName();
107 current = new_xbt_graph_node(graph, link_name, nodes);
108 new_xbt_graph_edge(graph, previous, current, edges);
111 new_xbt_graph_edge(graph, current, backboneNode, edges);
113 new_xbt_graph_edge(graph, current, routerNode, edges);
118 if (info.link_down) { // link down
119 const char *link_name = static_cast<simgrid::surf::Resource*>(
120 info.link_down)->getName();
121 current = new_xbt_graph_node(graph, link_name, nodes);
122 new_xbt_graph_edge(graph, previous, current, edges);
125 new_xbt_graph_edge(graph, current, backboneNode, edges);
127 new_xbt_graph_edge(graph, current, routerNode, edges);
135 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
136 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
137 s_surf_parsing_link_up_down_t info;
138 char* link_id = bprintf("%s_link_%d", cluster->id, id);
140 memset(&link, 0, sizeof(link));
142 link.bandwidth = cluster->bw;
143 link.latency = cluster->lat;
144 link.initiallyOn = 1;
145 link.policy = cluster->sharing_policy;
146 sg_platf_new_link(&link);
148 if (link.policy == SURF_LINK_FULLDUPLEX) {
149 char *tmp_link = bprintf("%s_UP", link_id);
150 info.link_up = sg_link_by_name(tmp_link);
152 tmp_link = bprintf("%s_DOWN", link_id);
153 info.link_down = sg_link_by_name(tmp_link);
156 info.link_up = sg_link_by_name(link_id);
157 info.link_down = info.link_up;
159 xbt_dynar_set(p_linkUpDownList, position, &info);
163 int AsCluster::parsePU(NetCard *elm) {
164 XBT_DEBUG("Load process unit \"%s\"", elm->getName());
165 xbt_dynar_push_as(p_indexNetworkElm, NetCard*, elm);
166 return xbt_dynar_length(p_indexNetworkElm)-1;
169 int AsCluster::parseAS(NetCard *elm) {
170 XBT_DEBUG("Load Autonomous system \"%s\"", elm->getName());
171 xbt_dynar_push_as(p_indexNetworkElm, NetCard*, elm);
172 return xbt_dynar_length(p_indexNetworkElm)-1;