Logo AND Algorithmique Numérique Distribuée

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