Logo AND Algorithmique Numérique Distribuée

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