Logo AND Algorithmique Numérique Distribuée

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