Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[pvs] The 'gw_src' pointer was utilized before it was verified against nullptr.
[simgrid.git] / src / kernel / routing / FullZone.cpp
1 /* Copyright (c) 2009-2020. 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 #include "src/surf/network_interface.hpp"
9 #include "src/surf/xml/platf_private.hpp"
10 #include "surf/surf.hpp"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
13
14 #define TO_ROUTE_FULL(i, j) routing_table_[(i) + (j)*table_size]
15
16 namespace simgrid {
17 namespace kernel {
18 namespace routing {
19 FullZone::FullZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
20     : RoutedZone(father, name, netmodel)
21 {
22 }
23
24 void FullZone::seal()
25 {
26   unsigned int table_size = get_table_size();
27
28   /* Create table if needed */
29   if (routing_table_.empty())
30     routing_table_.resize(table_size * table_size, nullptr);
31
32   /* Add the loopback if needed */
33   if (network_model_->loopback_ && hierarchy_ == RoutingMode::base) {
34     for (unsigned int i = 0; i < table_size; i++) {
35       RouteCreationArgs* route = TO_ROUTE_FULL(i, i);
36       if (not route) {
37         route = new RouteCreationArgs();
38         route->link_list.push_back(network_model_->loopback_);
39         TO_ROUTE_FULL(i, i) = route;
40       }
41     }
42   }
43 }
44
45 FullZone::~FullZone()
46 {
47   /* Delete routing table */
48   for (auto const* route : routing_table_)
49     delete route;
50 }
51
52 void FullZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* res, double* lat)
53 {
54   XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
55
56   unsigned int table_size        = get_table_size();
57   const RouteCreationArgs* e_route = TO_ROUTE_FULL(src->id(), dst->id());
58
59   if (e_route != nullptr) {
60     res->gw_src = e_route->gw_src;
61     res->gw_dst = e_route->gw_dst;
62     for (auto const& link : e_route->link_list) {
63       res->link_list.push_back(link);
64       if (lat)
65         *lat += link->get_latency();
66     }
67   }
68 }
69
70 void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
71                          std::vector<resource::LinkImpl*>& link_list, bool symmetrical)
72 {
73   add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical);
74
75   unsigned int table_size = get_table_size();
76
77   if (routing_table_.empty())
78     routing_table_.resize(table_size * table_size, nullptr);
79
80   /* Check that the route does not already exist */
81   if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
82     xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
83                "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
84                src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname());
85   else
86     xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
87                "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(),
88                dst->get_cname());
89
90   /* Add the route to the base */
91   TO_ROUTE_FULL(src->id(), dst->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, true);
92
93   if (symmetrical && src != dst) {
94     if (gw_dst && gw_src) {
95       NetPoint* gw_tmp = gw_src;
96       gw_src           = gw_dst;
97       gw_dst           = gw_tmp;
98     }
99     if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
100       xbt_assert(
101           nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
102           "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
103           dst->get_cname(), gw_dst->get_cname(), src->get_cname(), gw_src->get_cname());
104     else
105       xbt_assert(nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
106                  "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
107                  dst->get_cname(), src->get_cname());
108
109     TO_ROUTE_FULL(dst->id(), src->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, false);
110   }
111 }
112 }
113 }
114 } // namespace