1 /* Copyright (c) 2009-2023. The SimGrid Team. All rights reserved. */
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. */
6 #include <simgrid/kernel/routing/FullZone.hpp>
7 #include <simgrid/kernel/routing/NetPoint.hpp>
9 #include "src/kernel/resource/NetworkModel.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_full, ker_platform, "Kernel Full Routing");
14 namespace kernel::routing {
16 void FullZone::check_routing_table()
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_) {
28 void FullZone::do_seal()
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];
36 route.reset(new Route());
37 route->link_list_.push_back(get_network_model()->loopback_.get());
43 void FullZone::get_local_route(const NetPoint* src, const NetPoint* dst, Route* res, double* lat)
45 XBT_DEBUG("full getLocalRoute from %s[%lu] to %s[%lu]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
47 const auto& e_route = routing_table_[src->id()][dst->id()];
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);
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)
59 add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical);
61 check_routing_table();
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());
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(),
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));
77 if (symmetrical && src != dst) {
78 if (gw_dst && gw_src) {
79 NetPoint* gw_tmp = gw_src;
83 if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
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());
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());
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));
97 } // namespace kernel::routing
100 NetZone* create_full_zone(const std::string& name)
102 return (new kernel::routing::FullZone(name))->get_iface();
106 } // namespace simgrid