1 /* Copyright (c) 2009-2021. 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"
8 #include "src/surf/network_interface.hpp"
9 #include "surf/surf.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
13 #define TO_ROUTE_FULL(i, j) routing_table_[(i) + (j)*table_size]
19 void FullZone::do_seal()
21 unsigned int table_size = get_table_size();
23 /* Create table if needed */
24 if (routing_table_.empty())
25 routing_table_.resize(table_size * table_size, nullptr);
27 /* Add the loopback if needed */
28 if (get_network_model()->loopback_ && get_hierarchy() == RoutingMode::base) {
29 for (unsigned int i = 0; i < table_size; i++) {
30 Route* route = TO_ROUTE_FULL(i, i);
33 route->link_list_.push_back(get_network_model()->loopback_);
34 TO_ROUTE_FULL(i, i) = route;
42 /* Delete routing table */
43 for (auto const* route : routing_table_)
47 void FullZone::get_local_route(NetPoint* src, NetPoint* dst, Route* res, double* lat)
49 XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
51 unsigned int table_size = get_table_size();
52 const Route* e_route = TO_ROUTE_FULL(src->id(), dst->id());
54 if (e_route != nullptr) {
55 res->gw_src_ = e_route->gw_src_;
56 res->gw_dst_ = e_route->gw_dst_;
57 for (auto const& link : e_route->link_list_) {
58 res->link_list_.push_back(link);
60 *lat += link->get_latency();
65 void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
66 const std::vector<resource::LinkImpl*>& link_list, bool symmetrical)
68 add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical);
70 unsigned int table_size = get_table_size();
72 if (routing_table_.empty())
73 routing_table_.resize(table_size * table_size, nullptr);
75 /* Check that the route does not already exist */
76 if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
77 xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
78 "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
79 src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname());
81 xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
82 "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(),
85 /* Add the route to the base */
86 TO_ROUTE_FULL(src->id(), dst->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, true);
88 if (symmetrical && src != dst) {
89 if (gw_dst && gw_src) {
90 NetPoint* gw_tmp = gw_src;
94 if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
96 nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
97 "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
98 dst->get_cname(), gw_dst->get_cname(), src->get_cname(), gw_src->get_cname());
100 xbt_assert(nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
101 "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
102 dst->get_cname(), src->get_cname());
104 TO_ROUTE_FULL(dst->id(), src->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, false);
107 } // namespace routing
108 } // namespace kernel
111 NetZone* create_full_zone(const std::string& name)
113 return (new kernel::routing::FullZone(name))->get_iface();
117 } // namespace simgrid