Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Remove SIMIX_process_create_from_wrapper()
[simgrid.git] / src / surf / AsCluster.cpp
1 /* Copyright (c) 2009-2016. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/surf/AsCluster.hpp"
7 #include "src/surf/network_interface.hpp"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
10
11 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
12  * Note that a router is created, easing the interconnexion with the rest of the world. */
13
14 namespace simgrid {
15 namespace surf {
16   AsCluster::AsCluster(const char*name)
17     : AsImpl(name)
18   {}
19   AsCluster::~AsCluster()
20   {
21     xbt_dynar_free(&privateLinks_);
22   }
23
24 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
25 {
26   s_surf_parsing_link_up_down_t info;
27   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
28             src->name(), src->id(), dst->name(), dst->id());
29
30   if (! src->isRouter()) {    // No specific link for router
31
32     if((src->id() == dst->id()) && has_loopback_  ){
33       info = xbt_dynar_get_as(privateLinks_, src->id() * nb_links_per_node_, s_surf_parsing_link_up_down_t);
34       route->link_list->push_back(info.link_up);
35       if (lat)
36         *lat += info.link_up->getLatency();
37       return;
38     }
39
40
41     if (has_limiter_){          // limiter for sender
42       info = xbt_dynar_get_as(privateLinks_, src->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
43       route->link_list->push_back((Link*)info.link_up);
44     }
45
46     info = xbt_dynar_get_as(privateLinks_, src->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
47     if (info.link_up) {         // link up
48       route->link_list->push_back(info.link_up);
49       if (lat)
50         *lat += info.link_up->getLatency();
51     }
52
53   }
54
55   if (backbone_) {
56     route->link_list->push_back(backbone_);
57     if (lat)
58       *lat += backbone_->getLatency();
59   }
60
61   if (! dst->isRouter()) {    // No specific link for router
62     info = xbt_dynar_get_as(privateLinks_, dst->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
63
64     if (info.link_down) {       // link down
65       route->link_list->push_back(info.link_down);
66       if (lat)
67         *lat += info.link_down->getLatency();
68     }
69     if (has_limiter_){          // limiter for receiver
70         info = xbt_dynar_get_as(privateLinks_, dst->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
71         route->link_list->push_back(info.link_up);
72     }
73   }
74 }
75
76 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
77 {
78   int isrc;
79   int table_size = xbt_dynar_length(vertices_);
80
81   NetCard *src;
82   xbt_node_t current, previous, backboneNode = NULL, routerNode;
83   s_surf_parsing_link_up_down_t info;
84
85   xbt_assert(router_,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
86
87   /* create the router */
88   char *link_name = router_->name();
89   routerNode = new_xbt_graph_node(graph, link_name, nodes);
90
91   if(backbone_) {
92     const char *link_nameR = backbone_->getName();
93     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
94
95     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
96   }
97
98   for (isrc = 0; isrc < table_size; isrc++) {
99     src = xbt_dynar_get_as(vertices_, isrc, NetCard*);
100
101     if (! src->isRouter()) {
102       previous = new_xbt_graph_node(graph, src->name(), nodes);
103
104       info = xbt_dynar_get_as(privateLinks_, src->id(), s_surf_parsing_link_up_down_t);
105
106       if (info.link_up) {     // link up
107
108         const char *link_name = static_cast<simgrid::surf::Resource*>(
109           info.link_up)->getName();
110         current = new_xbt_graph_node(graph, link_name, nodes);
111         new_xbt_graph_edge(graph, previous, current, edges);
112
113         if (backbone_) {
114           new_xbt_graph_edge(graph, current, backboneNode, edges);
115         } else {
116           new_xbt_graph_edge(graph, current, routerNode, edges);
117         }
118
119       }
120
121       if (info.link_down) {    // link down
122         const char *link_name = static_cast<simgrid::surf::Resource*>(
123           info.link_down)->getName();
124         current = new_xbt_graph_node(graph, link_name, nodes);
125         new_xbt_graph_edge(graph, previous, current, edges);
126
127         if (backbone_) {
128           new_xbt_graph_edge(graph, current, backboneNode, edges);
129         } else {
130           new_xbt_graph_edge(graph, current, routerNode, edges);
131         }
132       }
133     }
134
135   }
136 }
137
138 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
139   s_surf_parsing_link_up_down_t info;
140   char* link_id = bprintf("%s_link_%d", cluster->id, id);
141
142   s_sg_platf_link_cbarg_t link;
143   memset(&link, 0, sizeof(link));
144   link.id = link_id;
145   link.bandwidth = cluster->bw;
146   link.latency = cluster->lat;
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 = Link::byName(tmp_link);
153     xbt_free(tmp_link);
154     tmp_link = bprintf("%s_DOWN", link_id);
155     info.link_down = Link::byName(tmp_link);
156     xbt_free(tmp_link);
157   } else {
158     info.link_up = info.link_down = Link::byName(link_id);
159   }
160   xbt_dynar_set(privateLinks_, position, &info);
161   xbt_free(link_id);
162 }
163
164 }
165 }