blob: 4a0ebd235cbce180f3448ec8c7ba549681fe6875 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08003 * Copyright (c) 2014-2020, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
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/>.
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070019 */
Nick Gordonb7b58392017-08-17 16:29:21 -050020
akmhoquefdbddb12014-05-02 18:35:19 -050021#ifndef NLSR_ROUTING_TABLE_HPP
22#define NLSR_ROUTING_TABLE_HPP
akmhoque53353462014-04-22 08:43:45 -050023
Nick Gordond0a7df32017-05-30 16:44:34 -050024#include "conf-parameter.hpp"
25#include "routing-table-entry.hpp"
Nick Gordonb7b58392017-08-17 16:29:21 -050026#include "signals.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060027#include "lsdb.hpp"
28#include "route/fib.hpp"
Ashlesh Gawande214032e2020-12-22 17:20:14 -050029#include "test-access-control.hpp"
Nick Gordond0a7df32017-05-30 16:44:34 -050030
Vince Lehman7c603292014-09-11 17:48:16 -050031#include <ndn-cxx/util/scheduler.hpp>
akmhoque53353462014-04-22 08:43:45 -050032
akmhoque53353462014-04-22 08:43:45 -050033namespace nlsr {
34
akmhoque53353462014-04-22 08:43:45 -050035class NextHop;
36
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070037/*! \brief Data abstraction for routing table status
38 *
39 * RtStatus := RT-STATUS-TYPE TLV-LENGTH
40 * RouteTableEntry*
41 *
42 * \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset
43 */
44class RoutingTableStatus
45{
46public:
47 using Error = ndn::tlv::Error;
48
49 RoutingTableStatus() = default;
50
51 RoutingTableStatus(const ndn::Block& block)
52 {
53 wireDecode(block);
54 }
55
56 const std::list<RoutingTableEntry>&
57 getRoutingTableEntry() const
58 {
59 return m_rTable;
60 }
61
62 const std::list<RoutingTableEntry>&
63 getDryRoutingTableEntry() const
64 {
65 return m_dryTable;
66 }
67
68 const ndn::Block&
69 wireEncode() const;
70
71private:
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
79PUBLIC_WITH_TESTS_ELSE_PROTECTED:
80 std::list<RoutingTableEntry> m_dryTable;
81 std::list<RoutingTableEntry> m_rTable;
82 mutable ndn::Block m_wire;
83};
84
85std::ostream&
86operator<<(std::ostream& os, const RoutingTableStatus& rts);
87
88class RoutingTable : public RoutingTableStatus
akmhoque53353462014-04-22 08:43:45 -050089{
90public:
laqinfan35731852017-08-08 06:17:39 -050091 explicit
Ashlesh Gawande85998a12017-12-07 22:22:13 -060092 RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb,
93 NamePrefixTable& namePrefixTable, ConfParameter& confParam);
Vince Lehman7b616582014-10-17 16:25:39 -050094
Nick G97e34942016-07-11 14:46:27 -050095 /*! \brief Calculates a list of next hops for each router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -050096 *
laqinfan35731852017-08-08 06:17:39 -050097 * Calculates the list of next hops to every other router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -050098 */
akmhoque53353462014-04-22 08:43:45 -050099 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600100 calculate();
akmhoque53353462014-04-22 08:43:45 -0500101
Nick G97e34942016-07-11 14:46:27 -0500102 /*! \brief Adds a next hop to a routing table entry.
laqinfan35731852017-08-08 06:17:39 -0500103 * \param destRouter The destination router whose RTE we want to modify.
104 * \param nh The next hop to add to the RTE.
Nick Gordond0a7df32017-05-30 16:44:34 -0500105 */
akmhoque53353462014-04-22 08:43:45 -0500106 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500107 addNextHop(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -0500108
Nick G97e34942016-07-11 14:46:27 -0500109 /*! \brief Adds a next hop to a routing table entry in a dry run scenario.
laqinfan35731852017-08-08 06:17:39 -0500110 * \param destRouter The destination router whose RTE we want to modify.
111 * \param nh The next hop to add to the router.
Nick Gordond0a7df32017-05-30 16:44:34 -0500112 */
akmhoque53353462014-04-22 08:43:45 -0500113 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500114 addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -0500115
akmhoqueb6450b12014-04-24 00:01:03 -0500116 RoutingTableEntry*
akmhoque31d1d4b2014-05-05 22:08:14 -0500117 findRoutingTableEntry(const ndn::Name& destRouter);
akmhoque53353462014-04-22 08:43:45 -0500118
Nick Gordond0a7df32017-05-30 16:44:34 -0500119 /*! \brief Schedules a calculation event in the event scheduler only
laqinfan35731852017-08-08 06:17:39 -0500120 * if one isn't already scheduled.
Nick Gordond0a7df32017-05-30 16:44:34 -0500121 */
akmhoque53353462014-04-22 08:43:45 -0500122 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600123 scheduleRoutingTableCalculation();
akmhoque53353462014-04-22 08:43:45 -0500124
Vince Lehman7b616582014-10-17 16:25:39 -0500125 void
126 setRoutingCalcInterval(uint32_t interval)
127 {
128 m_routingCalcInterval = ndn::time::seconds(interval);
129 }
130
131 const ndn::time::seconds&
132 getRoutingCalcInterval() const
133 {
134 return m_routingCalcInterval;
135 }
136
laqinfan35731852017-08-08 06:17:39 -0500137 uint64_t
138 getRtSize()
139 {
140 return m_rTable.size();
141 }
142
akmhoque53353462014-04-22 08:43:45 -0500143private:
Nick G97e34942016-07-11 14:46:27 -0500144 /*! \brief Calculates a link-state routing table. */
akmhoque53353462014-04-22 08:43:45 -0500145 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600146 calculateLsRoutingTable();
akmhoque53353462014-04-22 08:43:45 -0500147
Nick G97e34942016-07-11 14:46:27 -0500148 /*! \brief Calculates a HR routing table. */
akmhoque53353462014-04-22 08:43:45 -0500149 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600150 calculateHypRoutingTable(bool isDryRun);
akmhoque53353462014-04-22 08:43:45 -0500151
152 void
153 clearRoutingTable();
154
155 void
156 clearDryRoutingTable();
157
Nick Gordonb7b58392017-08-17 16:29:21 -0500158public:
Nick Gordond40a5882017-09-05 15:34:58 -0500159 std::unique_ptr<AfterRoutingChange> afterRoutingChange;
Nick Gordonb7b58392017-08-17 16:29:21 -0500160
Vince Lehman7c603292014-09-11 17:48:16 -0500161private:
162 ndn::Scheduler& m_scheduler;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600163 Fib& m_fib;
164 Lsdb& m_lsdb;
165 NamePrefixTable& m_namePrefixTable;
Vince Lehman7c603292014-09-11 17:48:16 -0500166
Vince Lehman7b616582014-10-17 16:25:39 -0500167 ndn::time::seconds m_routingCalcInterval;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600168
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500169PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600170 bool m_isRoutingTableCalculating;
171 bool m_isRouteCalculationScheduled;
172
173 ConfParameter& m_confParam;
akmhoque53353462014-04-22 08:43:45 -0500174};
175
Nick Gordonfad8e252016-08-11 14:21:38 -0500176} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500177
Nick Gordond0a7df32017-05-30 16:44:34 -0500178#endif // NLSR_ROUTING_TABLE_HPP