Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
trimming zones
[simgrid.git] / src / kernel / routing / FullZone.cpp
1 /* Copyright (c) 2009-2021. 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
20 void FullZone::do_seal()
21 {
22   unsigned int table_size = get_table_size();
23
24   /* Create table if needed */
25   if (routing_table_.empty())
26     routing_table_.resize(table_size * table_size, nullptr);
27
28   /* Add the loopback if needed */
29   if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) {
30     for (unsigned int i = 0; i < table_size; i++) {
31       RouteCreationArgs* route = TO_ROUTE_FULL(i, i);
32       if (not route) {
33         route = new RouteCreationArgs();
34         route->link_list.push_back(get_network_model()->loopback_);
35         TO_ROUTE_FULL(i, i) = route;
36       }
37     }
38   }
39 }
40
41 FullZone::~FullZone()
42 {
43   /* Delete routing table */
44   for (auto const* route : routing_table_)
45     delete route;
46 }
47
48 void FullZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* res, double* lat)
49 {
50   XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
51
52   unsigned int table_size          = get_table_size();
53   const RouteCreationArgs* e_route = TO_ROUTE_FULL(src->id(), dst->id());
54
55   if (e_route != nullptr) {
56     res->gw_src = e_route->gw_src;
57     res->gw_dst = e_route->gw_dst;
58     for (auto const& link : e_route->link_list) {
59       res->link_list.push_back(link);
60       if (lat)
61         *lat += link->get_latency();
62     }
63   }
64 }
65
66 void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
67                          std::vector<resource::LinkImpl*>& link_list, bool symmetrical)
68 {
69   add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical);
70
71   unsigned int table_size = get_table_size();
72
73   if (routing_table_.empty())
74     routing_table_.resize(table_size * table_size, nullptr);
75
76   /* Check that the route does not already exist */
77   if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
78     xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
79                "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
80                src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname());
81   else
82     xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
83                "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(),
84                dst->get_cname());
85
86   /* Add the route to the base */
87   TO_ROUTE_FULL(src->id(), dst->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, true);
88
89   if (symmetrical && src != dst) {
90     if (gw_dst && gw_src) {
91       NetPoint* gw_tmp = gw_src;
92       gw_src           = gw_dst;
93       gw_dst           = gw_tmp;
94     }
95     if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
96       xbt_assert(
97           nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
98           "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
99           dst->get_cname(), gw_dst->get_cname(), src->get_cname(), gw_src->get_cname());
100     else
101       xbt_assert(nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
102                  "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
103                  dst->get_cname(), src->get_cname());
104
105     TO_ROUTE_FULL(dst->id(), src->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, false);
106   }
107 }
108 } // namespace routing
109 } // namespace kernel
110 } // namespace simgrid