blob: f43ad11faaea8a43eab75f9ed14cafd4b5ce20d7 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Saurab Dulal72b2b252019-01-22 16:58:08 -06003 * Copyright (c) 2014-2019, 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
akmhoque53353462014-04-22 08:43:45 -050031#include <iostream>
32#include <utility>
33#include <string>
akmhoquefdbddb12014-05-02 18:35:19 -050034#include <boost/cstdint.hpp>
Vince Lehman7c603292014-09-11 17:48:16 -050035#include <ndn-cxx/util/scheduler.hpp>
akmhoque53353462014-04-22 08:43:45 -050036
akmhoque53353462014-04-22 08:43:45 -050037namespace nlsr {
38
akmhoque53353462014-04-22 08:43:45 -050039class NextHop;
40
laqinfan35731852017-08-08 06:17:39 -050041class RoutingTable : boost::noncopyable
akmhoque53353462014-04-22 08:43:45 -050042{
43public:
laqinfan35731852017-08-08 06:17:39 -050044 explicit
Ashlesh Gawande85998a12017-12-07 22:22:13 -060045 RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb,
46 NamePrefixTable& namePrefixTable, ConfParameter& confParam);
Vince Lehman7b616582014-10-17 16:25:39 -050047
Nick G97e34942016-07-11 14:46:27 -050048 /*! \brief Calculates a list of next hops for each router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -050049 *
laqinfan35731852017-08-08 06:17:39 -050050 * Calculates the list of next hops to every other router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -050051 */
akmhoque53353462014-04-22 08:43:45 -050052 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -060053 calculate();
akmhoque53353462014-04-22 08:43:45 -050054
Nick G97e34942016-07-11 14:46:27 -050055 /*! \brief Adds a next hop to a routing table entry.
laqinfan35731852017-08-08 06:17:39 -050056 * \param destRouter The destination router whose RTE we want to modify.
57 * \param nh The next hop to add to the RTE.
Nick Gordond0a7df32017-05-30 16:44:34 -050058 */
akmhoque53353462014-04-22 08:43:45 -050059 void
akmhoque31d1d4b2014-05-05 22:08:14 -050060 addNextHop(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050061
Nick G97e34942016-07-11 14:46:27 -050062 /*! \brief Adds a next hop to a routing table entry in a dry run scenario.
laqinfan35731852017-08-08 06:17:39 -050063 * \param destRouter The destination router whose RTE we want to modify.
64 * \param nh The next hop to add to the router.
Nick Gordond0a7df32017-05-30 16:44:34 -050065 */
akmhoque53353462014-04-22 08:43:45 -050066 void
akmhoque31d1d4b2014-05-05 22:08:14 -050067 addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050068
akmhoqueb6450b12014-04-24 00:01:03 -050069 RoutingTableEntry*
akmhoque31d1d4b2014-05-05 22:08:14 -050070 findRoutingTableEntry(const ndn::Name& destRouter);
akmhoque53353462014-04-22 08:43:45 -050071
Nick Gordond0a7df32017-05-30 16:44:34 -050072 /*! \brief Schedules a calculation event in the event scheduler only
laqinfan35731852017-08-08 06:17:39 -050073 * if one isn't already scheduled.
Nick Gordond0a7df32017-05-30 16:44:34 -050074 */
akmhoque53353462014-04-22 08:43:45 -050075 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -060076 scheduleRoutingTableCalculation();
akmhoque53353462014-04-22 08:43:45 -050077
78 int
79 getNoNextHop()
80 {
81 return m_NO_NEXT_HOP;
82 }
83
Vince Lehman7b616582014-10-17 16:25:39 -050084 void
85 setRoutingCalcInterval(uint32_t interval)
86 {
87 m_routingCalcInterval = ndn::time::seconds(interval);
88 }
89
90 const ndn::time::seconds&
91 getRoutingCalcInterval() const
92 {
93 return m_routingCalcInterval;
94 }
95
laqinfan35731852017-08-08 06:17:39 -050096 const std::list<RoutingTableEntry>&
97 getRoutingTableEntry() const
98 {
99 return m_rTable;
100 }
101
102 const std::list<RoutingTableEntry>&
103 getDryRoutingTableEntry() const
104 {
105 return m_dryTable;
106 }
107
108 uint64_t
109 getRtSize()
110 {
111 return m_rTable.size();
112 }
113
akmhoque53353462014-04-22 08:43:45 -0500114private:
Nick G97e34942016-07-11 14:46:27 -0500115 /*! \brief Calculates a link-state routing table. */
akmhoque53353462014-04-22 08:43:45 -0500116 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600117 calculateLsRoutingTable();
akmhoque53353462014-04-22 08:43:45 -0500118
Nick G97e34942016-07-11 14:46:27 -0500119 /*! \brief Calculates a HR routing table. */
akmhoque53353462014-04-22 08:43:45 -0500120 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600121 calculateHypRoutingTable(bool isDryRun);
akmhoque53353462014-04-22 08:43:45 -0500122
123 void
124 clearRoutingTable();
125
126 void
127 clearDryRoutingTable();
128
akmhoque674b0b12014-05-20 14:33:28 -0500129 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600130 writeLog();
akmhoque674b0b12014-05-20 14:33:28 -0500131
Nick Gordonb7b58392017-08-17 16:29:21 -0500132public:
Nick Gordond40a5882017-09-05 15:34:58 -0500133 std::unique_ptr<AfterRoutingChange> afterRoutingChange;
Nick Gordonb7b58392017-08-17 16:29:21 -0500134
135PUBLIC_WITH_TESTS_ELSE_PRIVATE:
136 std::list<RoutingTableEntry> m_rTable;
137
Vince Lehman7c603292014-09-11 17:48:16 -0500138private:
139 ndn::Scheduler& m_scheduler;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600140 Fib& m_fib;
141 Lsdb& m_lsdb;
142 NamePrefixTable& m_namePrefixTable;
Vince Lehman7c603292014-09-11 17:48:16 -0500143
akmhoque53353462014-04-22 08:43:45 -0500144 const int m_NO_NEXT_HOP;
145
akmhoque53353462014-04-22 08:43:45 -0500146 std::list<RoutingTableEntry> m_dryTable;
Vince Lehman7b616582014-10-17 16:25:39 -0500147
148 ndn::time::seconds m_routingCalcInterval;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600149
150 bool m_isRoutingTableCalculating;
151 bool m_isRouteCalculationScheduled;
152
153 ConfParameter& m_confParam;
akmhoque53353462014-04-22 08:43:45 -0500154};
155
Nick Gordonfad8e252016-08-11 14:21:38 -0500156} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500157
Nick Gordond0a7df32017-05-30 16:44:34 -0500158#endif // NLSR_ROUTING_TABLE_HPP