Logo AND Algorithmique Numérique Distribuée

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