Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the scope of some #include, and cut useless ones
[simgrid.git] / src / kernel / routing / FullZone.cpp
1 /* Copyright (c) 2009-2018. 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 "simgrid/kernel/routing/FullZone.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "src/surf/network_interface.hpp"
9 #include "src/surf/xml/platf_private.hpp"
10 #include "surf/surf.hpp"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
13
14 #define TO_ROUTE_FULL(i, j) routing_table_[(i) + (j)*table_size]
15
16 namespace simgrid {
17 namespace kernel {
18 namespace routing {
19 FullZone::FullZone(NetZone* father, std::string name) : RoutedZone(father, name)
20 {
21 }
22
23 void FullZone::seal()
24 {
25   unsigned int table_size = getTableSize();
26
27   /* Create table if needed */
28   if (not routing_table_)
29     routing_table_ = new RouteCreationArgs*[table_size * table_size]();
30
31   /* Add the loopback if needed */
32   if (surf_network_model->loopback_ && hierarchy_ == RoutingMode::base) {
33     for (unsigned int i = 0; i < table_size; i++) {
34       RouteCreationArgs* e_route = TO_ROUTE_FULL(i, i);
35       if (not e_route) {
36         e_route = new RouteCreationArgs();
37         e_route->link_list.push_back(surf_network_model->loopback_);
38         TO_ROUTE_FULL(i, i) = e_route;
39       }
40     }
41   }
42 }
43
44 FullZone::~FullZone()
45 {
46   if (routing_table_) {
47     unsigned int table_size = getTableSize();
48     /* Delete routing table */
49     for (unsigned int i = 0; i < table_size; i++)
50       for (unsigned int j = 0; j < table_size; j++)
51         delete TO_ROUTE_FULL(i, j);
52     delete[] routing_table_;
53   }
54 }
55
56 void FullZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* res, double* lat)
57 {
58   XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
59
60   unsigned int table_size        = getTableSize();
61   RouteCreationArgs* e_route     = TO_ROUTE_FULL(src->id(), dst->id());
62
63   if (e_route != nullptr) {
64     res->gw_src = e_route->gw_src;
65     res->gw_dst = e_route->gw_dst;
66     for (auto const& link : e_route->link_list) {
67       res->link_list.push_back(link);
68       if (lat)
69         *lat += link->latency();
70     }
71   }
72 }
73
74 void FullZone::add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
75                          kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
76                          std::vector<simgrid::surf::LinkImpl*>& link_list, bool symmetrical)
77 {
78   addRouteCheckParams(src, dst, gw_src, gw_dst, link_list, symmetrical);
79
80   unsigned int table_size = getTableSize();
81
82   if (not routing_table_)
83     routing_table_ = new RouteCreationArgs*[table_size * table_size]();
84
85   /* Check that the route does not already exist */
86   if (gw_dst) // inter-zone route (to adapt the error message, if any)
87     xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
88                "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
89                src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname());
90   else
91     xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
92                "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(),
93                dst->get_cname());
94
95   /* Add the route to the base */
96   TO_ROUTE_FULL(src->id(), dst->id()) =
97       newExtendedRoute(hierarchy_, src, dst, gw_src, gw_dst, link_list, symmetrical, true);
98
99   if (symmetrical == true && src != dst) {
100     if (gw_dst && gw_src) {
101       NetPoint* gw_tmp = gw_src;
102       gw_src           = gw_dst;
103       gw_dst           = gw_tmp;
104     }
105     if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
106       xbt_assert(
107           nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
108           "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
109           dst->get_cname(), gw_dst->get_cname(), src->get_cname(), gw_src->get_cname());
110     else
111       xbt_assert(nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
112                  "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
113                  dst->get_cname(), src->get_cname());
114
115     TO_ROUTE_FULL(dst->id(), src->id()) =
116         newExtendedRoute(hierarchy_, src, dst, gw_src, gw_dst, link_list, symmetrical, false);
117   }
118 }
119 }
120 }
121 } // namespace