blob: c49eaecc35d3393ec50e06511b56ae5ab260453b [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/*
Junxiao Shi43f37a02023-08-09 00:09:00 +00003 * Copyright (c) 2014-2023, 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"
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070030#include "route/name-prefix-table.hpp"
Nick Gordond0a7df32017-05-30 16:44:34 -050031
Vince Lehman7c603292014-09-11 17:48:16 -050032#include <ndn-cxx/util/scheduler.hpp>
akmhoque53353462014-04-22 08:43:45 -050033
akmhoque53353462014-04-22 08:43:45 -050034namespace nlsr {
35
akmhoque53353462014-04-22 08:43:45 -050036class NextHop;
37
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070038/*! \brief Data abstraction for routing table status
39 *
40 * RtStatus := RT-STATUS-TYPE TLV-LENGTH
41 * RouteTableEntry*
42 *
43 * \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset
44 */
45class RoutingTableStatus
46{
47public:
48 using Error = ndn::tlv::Error;
49
50 RoutingTableStatus() = default;
51
52 RoutingTableStatus(const ndn::Block& block)
53 {
54 wireDecode(block);
55 }
56
57 const std::list<RoutingTableEntry>&
58 getRoutingTableEntry() const
59 {
60 return m_rTable;
61 }
62
63 const std::list<RoutingTableEntry>&
64 getDryRoutingTableEntry() const
65 {
66 return m_dryTable;
67 }
68
69 const ndn::Block&
70 wireEncode() const;
71
72private:
73 void
74 wireDecode(const ndn::Block& wire);
75
76 template<ndn::encoding::Tag TAG>
77 size_t
78 wireEncode(ndn::EncodingImpl<TAG>& block) const;
79
80PUBLIC_WITH_TESTS_ELSE_PROTECTED:
81 std::list<RoutingTableEntry> m_dryTable;
82 std::list<RoutingTableEntry> m_rTable;
83 mutable ndn::Block m_wire;
84};
85
86std::ostream&
87operator<<(std::ostream& os, const RoutingTableStatus& rts);
88
89class RoutingTable : public RoutingTableStatus
akmhoque53353462014-04-22 08:43:45 -050090{
91public:
laqinfan35731852017-08-08 06:17:39 -050092 explicit
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070093 RoutingTable(ndn::Scheduler& scheduler, Lsdb& lsdb, ConfParameter& confParam);
94
95 ~RoutingTable()
96 {
97 m_afterLsdbModified.disconnect();
98 }
Vince Lehman7b616582014-10-17 16:25:39 -050099
Nick G97e34942016-07-11 14:46:27 -0500100 /*! \brief Calculates a list of next hops for each router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -0500101 *
laqinfan35731852017-08-08 06:17:39 -0500102 * Calculates the list of next hops to every other router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -0500103 */
akmhoque53353462014-04-22 08:43:45 -0500104 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600105 calculate();
akmhoque53353462014-04-22 08:43:45 -0500106
Nick G97e34942016-07-11 14:46:27 -0500107 /*! \brief Adds a next hop to a routing table entry.
laqinfan35731852017-08-08 06:17:39 -0500108 * \param destRouter The destination router whose RTE we want to modify.
109 * \param nh The next hop to add to the RTE.
Nick Gordond0a7df32017-05-30 16:44:34 -0500110 */
akmhoque53353462014-04-22 08:43:45 -0500111 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500112 addNextHop(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -0500113
Nick G97e34942016-07-11 14:46:27 -0500114 /*! \brief Adds a next hop to a routing table entry in a dry run scenario.
laqinfan35731852017-08-08 06:17:39 -0500115 * \param destRouter The destination router whose RTE we want to modify.
116 * \param nh The next hop to add to the router.
Nick Gordond0a7df32017-05-30 16:44:34 -0500117 */
akmhoque53353462014-04-22 08:43:45 -0500118 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500119 addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -0500120
akmhoqueb6450b12014-04-24 00:01:03 -0500121 RoutingTableEntry*
akmhoque31d1d4b2014-05-05 22:08:14 -0500122 findRoutingTableEntry(const ndn::Name& destRouter);
akmhoque53353462014-04-22 08:43:45 -0500123
Nick Gordond0a7df32017-05-30 16:44:34 -0500124 /*! \brief Schedules a calculation event in the event scheduler only
laqinfan35731852017-08-08 06:17:39 -0500125 * if one isn't already scheduled.
Nick Gordond0a7df32017-05-30 16:44:34 -0500126 */
akmhoque53353462014-04-22 08:43:45 -0500127 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600128 scheduleRoutingTableCalculation();
akmhoque53353462014-04-22 08:43:45 -0500129
akmhoque53353462014-04-22 08:43:45 -0500130private:
Nick G97e34942016-07-11 14:46:27 -0500131 /*! \brief Calculates a link-state routing table. */
akmhoque53353462014-04-22 08:43:45 -0500132 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600133 calculateLsRoutingTable();
akmhoque53353462014-04-22 08:43:45 -0500134
Nick G97e34942016-07-11 14:46:27 -0500135 /*! \brief Calculates a HR routing table. */
akmhoque53353462014-04-22 08:43:45 -0500136 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600137 calculateHypRoutingTable(bool isDryRun);
akmhoque53353462014-04-22 08:43:45 -0500138
139 void
140 clearRoutingTable();
141
142 void
143 clearDryRoutingTable();
144
Nick Gordonb7b58392017-08-17 16:29:21 -0500145public:
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700146 AfterRoutingChange afterRoutingChange;
Nick Gordonb7b58392017-08-17 16:29:21 -0500147
Vince Lehman7c603292014-09-11 17:48:16 -0500148private:
149 ndn::Scheduler& m_scheduler;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600150 Lsdb& m_lsdb;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600151
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500152PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700153 ndn::time::seconds m_routingCalcInterval;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600154 bool m_isRoutingTableCalculating;
155 bool m_isRouteCalculationScheduled;
156
157 ConfParameter& m_confParam;
Junxiao Shi43f37a02023-08-09 00:09:00 +0000158 ndn::signal::Connection m_afterLsdbModified;
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700159 int32_t m_hyperbolicState;
160 bool m_ownAdjLsaExist = false;
akmhoque53353462014-04-22 08:43:45 -0500161};
162
Nick Gordonfad8e252016-08-11 14:21:38 -0500163} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500164
Nick Gordond0a7df32017-05-30 16:44:34 -0500165#endif // NLSR_ROUTING_TABLE_HPP