Logo AND Algorithmique Numérique Distribuée

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