1 /* Copyright (c) 2009-2022. 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/StandardLinkImpl.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_full, ker_routing, "Kernel Full Routing");
17 void FullZone::check_routing_table()
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_) {
29 void FullZone::do_seal()
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];
37 route.reset(new Route());
38 route->link_list_.push_back(get_network_model()->loopback_);
44 void FullZone::get_local_route(const NetPoint* src, const NetPoint* dst, Route* res, double* lat)
46 XBT_DEBUG("full getLocalRoute from %s[%lu] to %s[%lu]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
48 const auto& e_route = routing_table_[src->id()][dst->id()];
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);
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)
60 add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical);
62 check_routing_table();
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());
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(),
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));
78 if (symmetrical && src != dst) {
79 if (gw_dst && gw_src) {
80 NetPoint* gw_tmp = gw_src;
84 if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
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());
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());
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));
98 } // namespace routing
102 NetZone* create_full_zone(const std::string& name)
104 return (new kernel::routing::FullZone(name))->get_iface();
108 } // namespace simgrid