blob: 5572aed275477e825e26c538c9147c0d01a167f8 [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"
Nick Gordond0a7df32017-05-30 16:44:34 -050028
akmhoque53353462014-04-22 08:43:45 -050029#include <iostream>
30#include <utility>
31#include <string>
akmhoquefdbddb12014-05-02 18:35:19 -050032#include <boost/cstdint.hpp>
Vince Lehman7c603292014-09-11 17:48:16 -050033#include <ndn-cxx/util/scheduler.hpp>
akmhoque53353462014-04-22 08:43:45 -050034
akmhoque53353462014-04-22 08:43:45 -050035namespace nlsr {
36
37class Nlsr;
38class NextHop;
39
laqinfan35731852017-08-08 06:17:39 -050040class RoutingTable : boost::noncopyable
akmhoque53353462014-04-22 08:43:45 -050041{
42public:
laqinfan35731852017-08-08 06:17:39 -050043 explicit
Nick Gordonb7b58392017-08-17 16:29:21 -050044 RoutingTable(ndn::Scheduler& scheduler);
Vince Lehman7b616582014-10-17 16:25:39 -050045
Nick G97e34942016-07-11 14:46:27 -050046 /*! \brief Calculates a list of next hops for each router in the network.
laqinfan35731852017-08-08 06:17:39 -050047 * \param nlsr The NLSR object that contains the LSAs needed for adj. info.
Nick Gordond0a7df32017-05-30 16:44:34 -050048 *
laqinfan35731852017-08-08 06:17:39 -050049 * Calculates the list of next hops to every other router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -050050 */
akmhoque53353462014-04-22 08:43:45 -050051 void
laqinfan35731852017-08-08 06:17:39 -050052 calculate(Nlsr& nlsr);
akmhoque53353462014-04-22 08:43:45 -050053
Nick G97e34942016-07-11 14:46:27 -050054 /*! \brief Adds a next hop to a routing table entry.
laqinfan35731852017-08-08 06:17:39 -050055 * \param destRouter The destination router whose RTE we want to modify.
56 * \param nh The next hop to add to the RTE.
Nick Gordond0a7df32017-05-30 16:44:34 -050057 */
akmhoque53353462014-04-22 08:43:45 -050058 void
akmhoque31d1d4b2014-05-05 22:08:14 -050059 addNextHop(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050060
Nick G97e34942016-07-11 14:46:27 -050061 /*! \brief Adds a next hop to a routing table entry in a dry run scenario.
laqinfan35731852017-08-08 06:17:39 -050062 * \param destRouter The destination router whose RTE we want to modify.
63 * \param nh The next hop to add to the router.
Nick Gordond0a7df32017-05-30 16:44:34 -050064 */
akmhoque53353462014-04-22 08:43:45 -050065 void
akmhoque31d1d4b2014-05-05 22:08:14 -050066 addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050067
akmhoqueb6450b12014-04-24 00:01:03 -050068 RoutingTableEntry*
akmhoque31d1d4b2014-05-05 22:08:14 -050069 findRoutingTableEntry(const ndn::Name& destRouter);
akmhoque53353462014-04-22 08:43:45 -050070
Nick Gordond0a7df32017-05-30 16:44:34 -050071 /*! \brief Schedules a calculation event in the event scheduler only
laqinfan35731852017-08-08 06:17:39 -050072 * if one isn't already scheduled.
73 * \param pnlsr The NLSR whose scheduling status is needed.
Nick Gordond0a7df32017-05-30 16:44:34 -050074 */
akmhoque53353462014-04-22 08:43:45 -050075 void
76 scheduleRoutingTableCalculation(Nlsr& pnlsr);
77
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
117 calculateLsRoutingTable(Nlsr& pnlsr);
118
Nick G97e34942016-07-11 14:46:27 -0500119 /*! \brief Calculates a HR routing table. */
akmhoque53353462014-04-22 08:43:45 -0500120 void
Saurab Dulal72b2b252019-01-22 16:58:08 -0600121 calculateHypRoutingTable(Nlsr& pnlsr, 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
akmhoquedcee9362014-08-05 22:58:01 -0500130 writeLog(int hyperbolicState);
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;
140
akmhoque53353462014-04-22 08:43:45 -0500141 const int m_NO_NEXT_HOP;
142
akmhoque53353462014-04-22 08:43:45 -0500143 std::list<RoutingTableEntry> m_dryTable;
Vince Lehman7b616582014-10-17 16:25:39 -0500144
145 ndn::time::seconds m_routingCalcInterval;
akmhoque53353462014-04-22 08:43:45 -0500146};
147
Nick Gordonfad8e252016-08-11 14:21:38 -0500148} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500149
Nick Gordond0a7df32017-05-30 16:44:34 -0500150#endif // NLSR_ROUTING_TABLE_HPP