blob: af2ba9380da26f7e8c0cc5dfc98e2b7e38d345e5 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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/>.
19 *
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Nick Gordonb7b58392017-08-17 16:29:21 -050021
akmhoquefdbddb12014-05-02 18:35:19 -050022#ifndef NLSR_ROUTING_TABLE_HPP
23#define NLSR_ROUTING_TABLE_HPP
akmhoque53353462014-04-22 08:43:45 -050024
Nick Gordond0a7df32017-05-30 16:44:34 -050025#include "conf-parameter.hpp"
26#include "routing-table-entry.hpp"
Nick Gordonb7b58392017-08-17 16:29:21 -050027#include "signals.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060028#include "lsdb.hpp"
29#include "route/fib.hpp"
Nick Gordond0a7df32017-05-30 16:44:34 -050030
akmhoquefdbddb12014-05-02 18:35:19 -050031#include <boost/cstdint.hpp>
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
laqinfan35731852017-08-08 06:17:39 -050038class RoutingTable : boost::noncopyable
akmhoque53353462014-04-22 08:43:45 -050039{
40public:
laqinfan35731852017-08-08 06:17:39 -050041 explicit
Ashlesh Gawande85998a12017-12-07 22:22:13 -060042 RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb,
43 NamePrefixTable& namePrefixTable, ConfParameter& confParam);
Vince Lehman7b616582014-10-17 16:25:39 -050044
Nick G97e34942016-07-11 14:46:27 -050045 /*! \brief Calculates a list of next hops for each router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -050046 *
laqinfan35731852017-08-08 06:17:39 -050047 * Calculates the list of next hops to every other router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -050048 */
akmhoque53353462014-04-22 08:43:45 -050049 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -060050 calculate();
akmhoque53353462014-04-22 08:43:45 -050051
Nick G97e34942016-07-11 14:46:27 -050052 /*! \brief Adds a next hop to a routing table entry.
laqinfan35731852017-08-08 06:17:39 -050053 * \param destRouter The destination router whose RTE we want to modify.
54 * \param nh The next hop to add to the RTE.
Nick Gordond0a7df32017-05-30 16:44:34 -050055 */
akmhoque53353462014-04-22 08:43:45 -050056 void
akmhoque31d1d4b2014-05-05 22:08:14 -050057 addNextHop(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050058
Nick G97e34942016-07-11 14:46:27 -050059 /*! \brief Adds a next hop to a routing table entry in a dry run scenario.
laqinfan35731852017-08-08 06:17:39 -050060 * \param destRouter The destination router whose RTE we want to modify.
61 * \param nh The next hop to add to the router.
Nick Gordond0a7df32017-05-30 16:44:34 -050062 */
akmhoque53353462014-04-22 08:43:45 -050063 void
akmhoque31d1d4b2014-05-05 22:08:14 -050064 addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050065
akmhoqueb6450b12014-04-24 00:01:03 -050066 RoutingTableEntry*
akmhoque31d1d4b2014-05-05 22:08:14 -050067 findRoutingTableEntry(const ndn::Name& destRouter);
akmhoque53353462014-04-22 08:43:45 -050068
Nick Gordond0a7df32017-05-30 16:44:34 -050069 /*! \brief Schedules a calculation event in the event scheduler only
laqinfan35731852017-08-08 06:17:39 -050070 * if one isn't already scheduled.
Nick Gordond0a7df32017-05-30 16:44:34 -050071 */
akmhoque53353462014-04-22 08:43:45 -050072 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -060073 scheduleRoutingTableCalculation();
akmhoque53353462014-04-22 08:43:45 -050074
Vince Lehman7b616582014-10-17 16:25:39 -050075 void
76 setRoutingCalcInterval(uint32_t interval)
77 {
78 m_routingCalcInterval = ndn::time::seconds(interval);
79 }
80
81 const ndn::time::seconds&
82 getRoutingCalcInterval() const
83 {
84 return m_routingCalcInterval;
85 }
86
laqinfan35731852017-08-08 06:17:39 -050087 const std::list<RoutingTableEntry>&
88 getRoutingTableEntry() const
89 {
90 return m_rTable;
91 }
92
93 const std::list<RoutingTableEntry>&
94 getDryRoutingTableEntry() const
95 {
96 return m_dryTable;
97 }
98
99 uint64_t
100 getRtSize()
101 {
102 return m_rTable.size();
103 }
104
akmhoque53353462014-04-22 08:43:45 -0500105private:
Nick G97e34942016-07-11 14:46:27 -0500106 /*! \brief Calculates a link-state routing table. */
akmhoque53353462014-04-22 08:43:45 -0500107 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600108 calculateLsRoutingTable();
akmhoque53353462014-04-22 08:43:45 -0500109
Nick G97e34942016-07-11 14:46:27 -0500110 /*! \brief Calculates a HR routing table. */
akmhoque53353462014-04-22 08:43:45 -0500111 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600112 calculateHypRoutingTable(bool isDryRun);
akmhoque53353462014-04-22 08:43:45 -0500113
114 void
115 clearRoutingTable();
116
117 void
118 clearDryRoutingTable();
119
akmhoque674b0b12014-05-20 14:33:28 -0500120 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600121 writeLog();
akmhoque674b0b12014-05-20 14:33:28 -0500122
Nick Gordonb7b58392017-08-17 16:29:21 -0500123public:
Nick Gordond40a5882017-09-05 15:34:58 -0500124 std::unique_ptr<AfterRoutingChange> afterRoutingChange;
Nick Gordonb7b58392017-08-17 16:29:21 -0500125
126PUBLIC_WITH_TESTS_ELSE_PRIVATE:
127 std::list<RoutingTableEntry> m_rTable;
128
Vince Lehman7c603292014-09-11 17:48:16 -0500129private:
130 ndn::Scheduler& m_scheduler;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600131 Fib& m_fib;
132 Lsdb& m_lsdb;
133 NamePrefixTable& m_namePrefixTable;
Vince Lehman7c603292014-09-11 17:48:16 -0500134
akmhoque53353462014-04-22 08:43:45 -0500135 std::list<RoutingTableEntry> m_dryTable;
Vince Lehman7b616582014-10-17 16:25:39 -0500136
137 ndn::time::seconds m_routingCalcInterval;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600138
139 bool m_isRoutingTableCalculating;
140 bool m_isRouteCalculationScheduled;
141
142 ConfParameter& m_confParam;
akmhoque53353462014-04-22 08:43:45 -0500143};
144
Nick Gordonfad8e252016-08-11 14:21:38 -0500145} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500146
Nick Gordond0a7df32017-05-30 16:44:34 -0500147#endif // NLSR_ROUTING_TABLE_HPP