routing-table.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2020, The University of Memphis,
4  * Regents of the University of California
5  *
6  * This file is part of NLSR (Named-data Link State Routing).
7  * See AUTHORS.md for complete list of NLSR authors and contributors.
8  *
9  * NLSR is free software: you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License as published by the Free Software Foundation,
11  * either version 3 of the License, or (at your option) any later version.
12  *
13  * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef NLSR_ROUTING_TABLE_HPP
22 #define NLSR_ROUTING_TABLE_HPP
23 
24 #include "conf-parameter.hpp"
25 #include "routing-table-entry.hpp"
26 #include "signals.hpp"
27 #include "lsdb.hpp"
28 #include "route/fib.hpp"
29 
30 #include <boost/cstdint.hpp>
31 #include <ndn-cxx/util/scheduler.hpp>
32 
33 namespace nlsr {
34 
35 class NextHop;
36 
45 {
46 public:
48 
49  RoutingTableStatus() = default;
50 
51  RoutingTableStatus(const ndn::Block& block)
52  {
53  wireDecode(block);
54  }
55 
56  const std::list<RoutingTableEntry>&
58  {
59  return m_rTable;
60  }
61 
62  const std::list<RoutingTableEntry>&
64  {
65  return m_dryTable;
66  }
67 
68  const ndn::Block&
69  wireEncode() const;
70 
71 private:
72  void
73  wireDecode(const ndn::Block& wire);
74 
75  template<ndn::encoding::Tag TAG>
76  size_t
77  wireEncode(ndn::EncodingImpl<TAG>& block) const;
78 
80  std::list<RoutingTableEntry> m_dryTable;
81  std::list<RoutingTableEntry> m_rTable;
82  mutable ndn::Block m_wire;
83 };
84 
85 std::ostream&
86 operator<<(std::ostream& os, const RoutingTableStatus& rts);
87 
89 {
90 public:
91  explicit
92  RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb,
93  NamePrefixTable& namePrefixTable, ConfParameter& confParam);
94 
99  void
100  calculate();
101 
106  void
107  addNextHop(const ndn::Name& destRouter, NextHop& nh);
108 
113  void
114  addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh);
115 
117  findRoutingTableEntry(const ndn::Name& destRouter);
118 
122  void
123  scheduleRoutingTableCalculation();
124 
125  void
126  setRoutingCalcInterval(uint32_t interval)
127  {
128  m_routingCalcInterval = ndn::time::seconds(interval);
129  }
130 
131  const ndn::time::seconds&
133  {
134  return m_routingCalcInterval;
135  }
136 
137  uint64_t
139  {
140  return m_rTable.size();
141  }
142 
143 private:
145  void
146  calculateLsRoutingTable();
147 
149  void
150  calculateHypRoutingTable(bool isDryRun);
151 
152  void
153  clearRoutingTable();
154 
155  void
156  clearDryRoutingTable();
157 
158 public:
159  std::unique_ptr<AfterRoutingChange> afterRoutingChange;
160 
161 private:
162  ndn::Scheduler& m_scheduler;
163  Fib& m_fib;
164  Lsdb& m_lsdb;
165  NamePrefixTable& m_namePrefixTable;
166 
167  ndn::time::seconds m_routingCalcInterval;
168 
169  bool m_isRoutingTableCalculating;
170  bool m_isRouteCalculationScheduled;
171 
172  ConfParameter& m_confParam;
173 };
174 
175 } // namespace nlsr
176 
177 #endif // NLSR_ROUTING_TABLE_HPP
A class to house all the configuration parameters for NLSR.
RoutingTableStatus(const ndn::Block &block)
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:181
const std::list< RoutingTableEntry > & getDryRoutingTableEntry() const
Maps names to lists of next hops, and exports this information to NFD.
Definition: fib.hpp:52
const ndn::Block & wireEncode() const
std::list< RoutingTableEntry > m_dryTable
std::list< RoutingTableEntry > m_rTable
void setRoutingCalcInterval(uint32_t interval)
Data abstraction for Nexthop.
Definition: nexthop.hpp:44
const std::list< RoutingTableEntry > & getRoutingTableEntry() const
Data abstraction for RouteTableInfo.
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Data abstraction for routing table status.
std::unique_ptr< AfterRoutingChange > afterRoutingChange
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
const ndn::time::seconds & getRoutingCalcInterval() const