Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove a useless dirty hack for SMPI+MSG
[simgrid.git] / src / kernel / routing / AsFull.cpp
1 /* Copyright (c) 2009-2016. The SimGrid Team. All rights reserved.          */
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 "src/kernel/routing/AsFull.hpp"
7 #include "src/surf/network_interface.hpp"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
10
11 #define TO_ROUTE_FULL(i,j) routingTable_[(i)+(j)*table_size]
12
13 namespace simgrid {
14 namespace kernel {
15 namespace routing {
16   AsFull::AsFull(const char*name)
17     : AsRoutedGraph(name)
18   {
19   }
20
21 void AsFull::seal() {
22   int i;
23   sg_platf_route_cbarg_t e_route;
24
25   /* set utils vars */
26   int table_size = (int)xbt_dynar_length(vertices_);
27
28   /* Create table if necessary */
29   if (!routingTable_)
30     routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
31
32   /* Add the loopback if needed */
33   if (routing_platf->loopback_ && hierarchy_ == RoutingMode::base) {
34     for (i = 0; i < table_size; i++) {
35       e_route = TO_ROUTE_FULL(i, i);
36       if (!e_route) {
37         e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
38         e_route->gw_src = nullptr;
39         e_route->gw_dst = nullptr;
40         e_route->link_list = new std::vector<Link*>();
41         e_route->link_list->push_back(routing_platf->loopback_);
42         TO_ROUTE_FULL(i, i) = e_route;
43       }
44     }
45   }
46 }
47
48 AsFull::~AsFull(){
49   if (routingTable_) {
50     int table_size = (int)xbt_dynar_length(vertices_);
51     int i, j;
52     /* Delete routing table */
53     for (i = 0; i < table_size; i++)
54       for (j = 0; j < table_size; j++) {
55         if (TO_ROUTE_FULL(i,j)){
56           delete TO_ROUTE_FULL(i,j)->link_list;
57           xbt_free(TO_ROUTE_FULL(i,j));
58         }
59       }
60     xbt_free(routingTable_);
61   }
62 }
63
64 void AsFull::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t res, double *lat)
65 {
66   XBT_DEBUG("full_get_route_and_latency from %s[%d] to %s[%d]",
67       src->name(), src->id(), dst->name(), dst->id());
68
69   /* set utils vars */
70   size_t table_size = xbt_dynar_length(vertices_);
71
72   sg_platf_route_cbarg_t e_route = nullptr;
73
74   e_route = TO_ROUTE_FULL(src->id(), dst->id());
75
76   if (e_route) {
77     res->gw_src = e_route->gw_src;
78     res->gw_dst = e_route->gw_dst;
79     for (auto link : *e_route->link_list) {
80       res->link_list->push_back(link);
81       if (lat)
82         *lat += static_cast<Link*>(link)->getLatency();
83     }
84   }
85 }
86
87 void AsFull::addRoute(sg_platf_route_cbarg_t route)
88 {
89   NetCard *src_net_elm = route->src;
90   NetCard *dst_net_elm = route->dst;
91   const char *src = src_net_elm->name();
92   const char *dst = dst_net_elm->name();
93
94   addRouteCheckParams(route);
95
96   size_t table_size = xbt_dynar_length(vertices_);
97
98   if (!routingTable_)
99     routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
100
101   /* Check that the route does not already exist */
102   if (route->gw_dst) // AS route (to adapt the error message, if any)
103     xbt_assert(nullptr == TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()),
104         "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
105         src,route->gw_src->name(),dst,route->gw_dst->name());
106   else
107     xbt_assert(nullptr == TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()),
108         "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src,dst);
109
110   /* Add the route to the base */
111   TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()) = newExtendedRoute(hierarchy_, route, 1);
112   TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id())->link_list->shrink_to_fit();
113
114   if (route->symmetrical == true && src_net_elm != dst_net_elm) {
115     if (route->gw_dst && route->gw_src) {
116       NetCard* gw_tmp = route->gw_src;
117       route->gw_src = route->gw_dst;
118       route->gw_dst = gw_tmp;
119     }
120     if (route->gw_dst) // AS route (to adapt the error message, if any)
121       xbt_assert(nullptr == TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()),
122           "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
123           dst,route->gw_dst->name(),src,route->gw_src->name());
124     else
125       xbt_assert(nullptr == TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()),
126           "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.", dst,src);
127
128     TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()) = newExtendedRoute(hierarchy_, route, 0);
129     TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id())->link_list->shrink_to_fit();
130   }
131 }
132
133 }}} // namespace