Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0e7a67a30692fb01f9b54cf03e2a708a7d67529f
[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 #include "surf_routing_private.h"
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 }
26
27 /* Business methods */
28 void AsCluster::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t route, double *lat)
29 {
30   s_surf_parsing_link_up_down_t info;
31   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
32             src->p_name, src->m_id, dst->p_name, dst->m_id);
33
34   if (src->p_rcType != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
35     info = xbt_dynar_get_as(p_linkUpDownList, src->m_id, s_surf_parsing_link_up_down_t);
36
37     if((src->m_id == dst->m_id) && info.loopback_link  ){
38       xbt_dynar_push_as(route->link_list, void *, info.loopback_link);
39       if (lat)
40         *lat += static_cast<NetworkCm02LinkPtr>(info.loopback_link)->getLatency();
41       return;
42     }
43
44
45     if (info.limiter_link)          // limiter for sender
46       xbt_dynar_push_as(route->link_list, void *, info.limiter_link);
47
48     if (info.link_up) {         // link up
49       xbt_dynar_push_as(route->link_list, void *, info.link_up);
50       if (lat)
51         *lat += static_cast<NetworkCm02LinkPtr>(info.link_up)->getLatency();
52     }
53   }
54
55   if (p_backbone) {
56     xbt_dynar_push_as(route->link_list, void *, p_backbone);
57     if (lat)
58       *lat += static_cast<NetworkCm02LinkPtr>(p_backbone)->getLatency();
59   }
60
61   if (dst->p_rcType != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
62     info =
63         xbt_dynar_get_as(p_linkUpDownList, dst->m_id, s_surf_parsing_link_up_down_t);
64     if (info.link_down) {       // link down
65       xbt_dynar_push_as(route->link_list, void *, info.link_down);
66       if (lat)
67         *lat += static_cast<NetworkCm02LinkPtr>(info.link_down)->getLatency();
68     }
69
70     if (info.limiter_link)          // limiter for receiver
71       xbt_dynar_push_as(route->link_list, void *, info.limiter_link);
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(p_indexNetworkElm);
80
81   RoutingEdgePtr src;
82   xbt_node_t current, previous, backboneNode = NULL, routerNode;
83   s_surf_parsing_link_up_down_t info;
84
85   xbt_assert(p_router,"Malformed cluster");
86
87   /* create the router */
88   char *link_name = p_router->p_name;
89   routerNode = new_xbt_graph_node(graph, link_name, nodes);
90
91   if(p_backbone) {
92     const char *link_nameR = p_backbone->m_name;
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(p_indexNetworkElm, isrc, RoutingEdgePtr);
100
101     if (src->p_rcType != SURF_NETWORK_ELEMENT_ROUTER) {
102       previous = new_xbt_graph_node(graph, src->p_name, nodes);
103
104       info = xbt_dynar_get_as(p_linkUpDownList, src->m_id, s_surf_parsing_link_up_down_t);
105
106       if (info.link_up) {     // link up
107
108         const char *link_name = ((ResourcePtr) info.link_up)->m_name;
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 = ((ResourcePtr) info.link_down)->m_name;
122         current = new_xbt_graph_node(graph, link_name, nodes);
123         new_xbt_graph_edge(graph, previous, current, edges);
124
125         if (p_backbone) {
126           new_xbt_graph_edge(graph, current, backboneNode, edges);
127         } else {
128           new_xbt_graph_edge(graph, current, routerNode, edges);
129         }
130       }
131     }
132
133   }
134 }
135
136 int AsCluster::parsePU(RoutingEdgePtr elm) {
137   XBT_DEBUG("Load process unit \"%s\"", elm->p_name);
138   xbt_dynar_push_as(p_indexNetworkElm, RoutingEdgePtr, elm);
139   return xbt_dynar_length(p_indexNetworkElm)-1;
140 }
141
142 int AsCluster::parseAS(RoutingEdgePtr elm) {
143   XBT_DEBUG("Load Autonomous system \"%s\"", elm->p_name);
144   xbt_dynar_push_as(p_indexNetworkElm, RoutingEdgePtr, elm);
145   return xbt_dynar_length(p_indexNetworkElm)-1;
146 }
147
148