1 /* Copyright (c) 2009-2018. 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 "src/surf/xml/platf_private.hpp"
10 #include "surf/surf.hpp"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
14 #define TO_ROUTE_FULL(i, j) routing_table_[(i) + (j)*table_size]
19 FullZone::FullZone(NetZoneImpl* father, std::string name) : RoutedZone(father, name) {}
23 unsigned int table_size = get_table_size();
25 /* Create table if needed */
26 if (not routing_table_)
27 routing_table_ = new RouteCreationArgs*[table_size * table_size]();
29 /* Add the loopback if needed */
30 if (surf_network_model->loopback_ && hierarchy_ == RoutingMode::base) {
31 for (unsigned int i = 0; i < table_size; i++) {
32 RouteCreationArgs* e_route = TO_ROUTE_FULL(i, i);
34 e_route = new RouteCreationArgs();
35 e_route->link_list.push_back(surf_network_model->loopback_);
36 TO_ROUTE_FULL(i, i) = e_route;
45 unsigned int table_size = get_table_size();
46 /* Delete routing table */
47 for (unsigned int i = 0; i < table_size; i++)
48 for (unsigned int j = 0; j < table_size; j++)
49 delete TO_ROUTE_FULL(i, j);
50 delete[] routing_table_;
54 void FullZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* res, double* lat)
56 XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
58 unsigned int table_size = get_table_size();
59 RouteCreationArgs* e_route = TO_ROUTE_FULL(src->id(), dst->id());
61 if (e_route != nullptr) {
62 res->gw_src = e_route->gw_src;
63 res->gw_dst = e_route->gw_dst;
64 for (auto const& link : e_route->link_list) {
65 res->link_list.push_back(link);
67 *lat += link->get_latency();
72 void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
73 std::vector<resource::LinkImpl*>& link_list, bool symmetrical)
75 add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical);
77 unsigned int table_size = get_table_size();
79 if (not routing_table_)
80 routing_table_ = new RouteCreationArgs*[table_size * table_size]();
82 /* Check that the route does not already exist */
83 if (gw_dst) // inter-zone route (to adapt the error message, if any)
84 xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
85 "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
86 src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname());
88 xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
89 "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(),
92 /* Add the route to the base */
93 TO_ROUTE_FULL(src->id(), dst->id()) =
94 new_extended_route(hierarchy_, src, dst, gw_src, gw_dst, link_list, symmetrical, true);
96 if (symmetrical == true && src != dst) {
97 if (gw_dst && gw_src) {
98 NetPoint* gw_tmp = gw_src;
102 if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
104 nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
105 "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
106 dst->get_cname(), gw_dst->get_cname(), src->get_cname(), gw_src->get_cname());
108 xbt_assert(nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
109 "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
110 dst->get_cname(), src->get_cname());
112 TO_ROUTE_FULL(dst->id(), src->id()) =
113 new_extended_route(hierarchy_, src, dst, gw_src, gw_dst, link_list, symmetrical, false);