Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
93503a102673ba120fa99d4f8056cb84728c24d2
[simgrid.git] / src / surf / surf_routing_cluster.cpp
1 /* Copyright (c) 2009, 2010, 2011, 2013. 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
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
15 AS_t model_cluster_create(void)
16 {
17   return new AsCluster();
18 }
19
20 /* Creation routing model functions */
21 AsCluster::AsCluster() : AsNone()
22 {
23   p_backbone = 0;
24   p_loopback = 0;
25   p_router = 0;
26   p_dimensions = NULL;
27   p_has_limiter = 0;
28   p_has_loopback = 0;
29 }
30
31 /* Business methods */
32 void AsCluster::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t route, double *lat)
33 {
34   s_surf_parsing_link_up_down_t info;
35   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
36             src->p_name, src->m_id, dst->p_name, dst->m_id);
37
38   //retrieve the number of links we stored for each node
39   int nb_links_per_node = p_has_loopback + p_has_limiter +
40       (p_dimensions ? xbt_dynar_length(p_dimensions) : 1);
41
42   if (src->p_rcType != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
43
44     if((src->m_id == dst->m_id) && p_has_loopback  ){
45       info = xbt_dynar_get_as(p_linkUpDownList, src->m_id * nb_links_per_node, s_surf_parsing_link_up_down_t);
46       xbt_dynar_push_as(route->link_list, void *, info.link_up);
47       if (lat)
48         *lat += static_cast<NetworkLinkPtr>(info.link_up)->getLatency();
49       return;
50     }
51
52
53     if (p_has_limiter){          // limiter for sender
54       info = xbt_dynar_get_as(p_linkUpDownList, src->m_id * nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
55       xbt_dynar_push_as(route->link_list, void *, info.link_up);
56     }
57
58     info = xbt_dynar_get_as(p_linkUpDownList, src->m_id * nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
59     if (info.link_up) {         // link up
60       xbt_dynar_push_as(route->link_list, void *, info.link_up);
61       if (lat)
62         *lat += static_cast<NetworkLinkPtr>(info.link_up)->getLatency();
63     }
64
65   }
66
67   if (p_backbone) {
68     xbt_dynar_push_as(route->link_list, void *, static_cast<ResourcePtr>(p_backbone));
69     if (lat)
70       *lat += p_backbone->getLatency();
71   }
72
73   if (dst->p_rcType != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
74     info = xbt_dynar_get_as(p_linkUpDownList, dst->m_id * nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
75
76     if (info.link_down) {       // link down
77       xbt_dynar_push_as(route->link_list, void *, info.link_down);
78       if (lat)
79         *lat += static_cast<NetworkLinkPtr>(info.link_down)->getLatency();
80     }
81     if (p_has_limiter){          // limiter for receiver
82         info = xbt_dynar_get_as(p_linkUpDownList, dst->m_id * nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
83         xbt_dynar_push_as(route->link_list, void *, info.link_up);
84     }
85   }
86 }
87
88 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
89 {
90   int isrc;
91   int table_size = xbt_dynar_length(p_indexNetworkElm);
92
93   RoutingEdgePtr src;
94   xbt_node_t current, previous, backboneNode = NULL, routerNode;
95   s_surf_parsing_link_up_down_t info;
96
97   xbt_assert(p_router,"Malformed cluster");
98
99   /* create the router */
100   char *link_name = p_router->p_name;
101   routerNode = new_xbt_graph_node(graph, link_name, nodes);
102
103   if(p_backbone) {
104     const char *link_nameR = p_backbone->getName();
105     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
106
107     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
108   }
109
110   for (isrc = 0; isrc < table_size; isrc++) {
111     src = xbt_dynar_get_as(p_indexNetworkElm, isrc, RoutingEdgePtr);
112
113     if (src->p_rcType != SURF_NETWORK_ELEMENT_ROUTER) {
114       previous = new_xbt_graph_node(graph, src->p_name, nodes);
115
116       info = xbt_dynar_get_as(p_linkUpDownList, src->m_id, s_surf_parsing_link_up_down_t);
117
118       if (info.link_up) {     // link up
119
120         const char *link_name = static_cast<ResourcePtr>(info.link_up)->getName();
121         current = new_xbt_graph_node(graph, link_name, nodes);
122         new_xbt_graph_edge(graph, previous, current, edges);
123
124         if (p_backbone) {
125           new_xbt_graph_edge(graph, current, backboneNode, edges);
126         } else {
127           new_xbt_graph_edge(graph, current, routerNode, edges);
128         }
129
130       }
131
132       if (info.link_down) {    // link down
133         const char *link_name = static_cast<ResourcePtr>(info.link_down)->getName();
134         current = new_xbt_graph_node(graph, link_name, nodes);
135         new_xbt_graph_edge(graph, previous, current, edges);
136
137         if (p_backbone) {
138           new_xbt_graph_edge(graph, current, backboneNode, edges);
139         } else {
140           new_xbt_graph_edge(graph, current, routerNode, edges);
141         }
142       }
143     }
144
145   }
146 }
147
148 int AsCluster::parsePU(RoutingEdgePtr elm) {
149   XBT_DEBUG("Load process unit \"%s\"", elm->p_name);
150   xbt_dynar_push_as(p_indexNetworkElm, RoutingEdgePtr, elm);
151   return xbt_dynar_length(p_indexNetworkElm)-1;
152 }
153
154 int AsCluster::parseAS(RoutingEdgePtr elm) {
155   XBT_DEBUG("Load Autonomous system \"%s\"", elm->p_name);
156   xbt_dynar_push_as(p_indexNetworkElm, RoutingEdgePtr, elm);
157   return xbt_dynar_length(p_indexNetworkElm)-1;
158 }
159
160