Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / kernel / routing / FullZone.cpp
1 /* Copyright (c) 2009-2023. 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
9 #include "src/kernel/resource/NetworkModel.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_full, ker_platform, "Kernel Full Routing");
12
13 namespace simgrid {
14 namespace kernel::routing {
15
16 void FullZone::check_routing_table()
17 {
18   unsigned int table_size = get_table_size();
19   /* assure routing_table is table_size X table_size */
20   if (routing_table_.size() != table_size) {
21     routing_table_.resize(table_size);
22     for (auto& j : routing_table_) {
23       j.resize(table_size);
24     }
25   }
26 }
27
28 void FullZone::do_seal()
29 {
30   check_routing_table();
31   /* Add the loopback if needed */
32   if (get_network_model()->loopback_ && get_hierarchy() == RoutingMode::base) {
33     for (unsigned int i = 0; i < get_table_size(); i++) {
34       auto& route = routing_table_[i][i];
35       if (not route) {
36         route.reset(new Route());
37         route->link_list_.push_back(get_network_model()->loopback_.get());
38       }
39     }
40   }
41 }
42
43 void FullZone::get_local_route(const NetPoint* src, const NetPoint* dst, Route* res, double* lat)
44 {
45   XBT_DEBUG("full getLocalRoute from %s[%lu] to %s[%lu]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
46
47   const auto& e_route = routing_table_[src->id()][dst->id()];
48
49   if (e_route != nullptr) {
50     res->gw_src_ = e_route->gw_src_;
51     res->gw_dst_ = e_route->gw_dst_;
52     add_link_latency(res->link_list_, e_route->link_list_, lat);
53   }
54 }
55
56 void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
57                          const std::vector<s4u::LinkInRoute>& link_list, bool symmetrical)
58 {
59   add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical);
60
61   check_routing_table();
62
63   /* Check that the route does not already exist */
64   if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
65     xbt_assert(nullptr == routing_table_[src->id()][dst->id()],
66                "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
67                src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname());
68   else
69     xbt_assert(nullptr == routing_table_[src->id()][dst->id()],
70                "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(),
71                dst->get_cname());
72
73   /* Add the route to the base */
74   routing_table_[src->id()][dst->id()] = std::unique_ptr<Route>(
75       new_extended_route(get_hierarchy(), gw_src, gw_dst, get_link_list_impl(link_list, false), true));
76
77   if (symmetrical && src != dst) {
78     if (gw_dst && gw_src) {
79       NetPoint* gw_tmp = gw_src;
80       gw_src           = gw_dst;
81       gw_dst           = gw_tmp;
82     }
83     if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
84       xbt_assert(
85           nullptr == routing_table_[dst->id()][src->id()],
86           "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
87           dst->get_cname(), gw_dst->get_cname(), src->get_cname(), gw_src->get_cname());
88     else
89       xbt_assert(nullptr == routing_table_[dst->id()][src->id()],
90                  "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
91                  dst->get_cname(), src->get_cname());
92
93     routing_table_[dst->id()][src->id()] = std::unique_ptr<Route>(
94         new_extended_route(get_hierarchy(), gw_src, gw_dst, get_link_list_impl(link_list, true), false));
95   }
96 }
97 } // namespace kernel::routing
98
99 namespace s4u {
100 NetZone* create_full_zone(const std::string& name)
101 {
102   return (new kernel::routing::FullZone(name))->get_iface();
103 }
104 } // namespace s4u
105
106 } // namespace simgrid