Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename a field and slightly improve the doc
[simgrid.git] / src / surf / surf_routing_cluster.cpp
1 /* Copyright (c) 2009-2011, 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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
7 #include "surf_routing_cluster.hpp"
8 #include "surf_routing_private.hpp"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
11
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.
14  */
15
16 namespace simgrid {
17 namespace surf {
18   AsCluster::AsCluster(const char*name)
19     : AsNone(name)
20   {}
21
22 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
23 {
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->getName(), src->getId(), dst->getName(), dst->getId());
27
28   if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
29
30     if((src->getId() == dst->getId()) && p_has_loopback  ){
31       info = xbt_dynar_get_as(upDownLinks, src->getId() * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
32       xbt_dynar_push_as(route->link_list, void *, info.link_up);
33       if (lat)
34         *lat += static_cast<Link*>(info.link_up)->getLatency();
35       return;
36     }
37
38
39     if (p_has_limiter){          // limiter for sender
40       info = xbt_dynar_get_as(upDownLinks, src->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
41       xbt_dynar_push_as(route->link_list, void *, info.link_up);
42     }
43
44     info = xbt_dynar_get_as(upDownLinks, src->getId() * p_nb_links_per_node + p_has_loopback + p_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);
47       if (lat)
48         *lat += static_cast<Link*>(info.link_up)->getLatency();
49     }
50
51   }
52
53   if (p_backbone) {
54     xbt_dynar_push_as(route->link_list, void *,
55       static_cast<simgrid::surf::Resource*>(p_backbone));
56     if (lat)
57       *lat += p_backbone->getLatency();
58   }
59
60   if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
61     info = xbt_dynar_get_as(upDownLinks, dst->getId() * p_nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
62
63     if (info.link_down) {       // link down
64       xbt_dynar_push_as(route->link_list, void *, info.link_down);
65       if (lat)
66         *lat += static_cast<Link*>(info.link_down)->getLatency();
67     }
68     if (p_has_limiter){          // limiter for receiver
69         info = xbt_dynar_get_as(upDownLinks, dst->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
70         xbt_dynar_push_as(route->link_list, void *, info.link_up);
71     }
72   }
73 }
74
75 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
76 {
77   int isrc;
78   int table_size = xbt_dynar_length(vertices_);
79
80   NetCard *src;
81   xbt_node_t current, previous, backboneNode = NULL, routerNode;
82   s_surf_parsing_link_up_down_t info;
83
84   xbt_assert(p_router,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
85
86   /* create the router */
87   char *link_name = p_router->getName();
88   routerNode = new_xbt_graph_node(graph, link_name, nodes);
89
90   if(p_backbone) {
91     const char *link_nameR = p_backbone->getName();
92     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
93
94     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
95   }
96
97   for (isrc = 0; isrc < table_size; isrc++) {
98     src = xbt_dynar_get_as(vertices_, isrc, NetCard*);
99
100     if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
101       previous = new_xbt_graph_node(graph, src->getName(), nodes);
102
103       info = xbt_dynar_get_as(upDownLinks, src->getId(), s_surf_parsing_link_up_down_t);
104
105       if (info.link_up) {     // link up
106
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);
111
112         if (p_backbone) {
113           new_xbt_graph_edge(graph, current, backboneNode, edges);
114         } else {
115           new_xbt_graph_edge(graph, current, routerNode, edges);
116         }
117
118       }
119
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);
125
126         if (p_backbone) {
127           new_xbt_graph_edge(graph, current, backboneNode, edges);
128         } else {
129           new_xbt_graph_edge(graph, current, routerNode, edges);
130         }
131       }
132     }
133
134   }
135 }
136
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);
141
142   memset(&link, 0, sizeof(link));
143   link.id = link_id;
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);
149
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);
153     xbt_free(tmp_link);
154     tmp_link = bprintf("%s_DOWN", link_id);
155     info.link_down = sg_link_by_name(tmp_link);
156     xbt_free(tmp_link);
157   } else {
158     info.link_up = sg_link_by_name(link_id);
159     info.link_down = info.link_up;
160   }
161   xbt_dynar_set(upDownLinks, position, &info);
162   xbt_free(link_id);
163 }
164
165 }
166 }