blob: b138c9dc6cf30f10af2e94700e60431a3f671eae [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoquefdbddb12014-05-02 18:35:19 -050023#ifndef NLSR_ROUTING_TABLE_HPP
24#define NLSR_ROUTING_TABLE_HPP
akmhoque53353462014-04-22 08:43:45 -050025
Nick Gordond0a7df32017-05-30 16:44:34 -050026#include "conf-parameter.hpp"
27#include "routing-table-entry.hpp"
28
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
40class RoutingTable
41{
42public:
Vince Lehman7c603292014-09-11 17:48:16 -050043 RoutingTable(ndn::Scheduler& scheduler)
44 : m_scheduler(scheduler)
45 , m_NO_NEXT_HOP(-12345)
Vince Lehman7b616582014-10-17 16:25:39 -050046 , m_routingCalcInterval(static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT))
akmhoque53353462014-04-22 08:43:45 -050047 {
48 }
Vince Lehman7b616582014-10-17 16:25:39 -050049
Nick G97e34942016-07-11 14:46:27 -050050 /*! \brief Calculates a list of next hops for each router in the network.
Nick Gordond0a7df32017-05-30 16:44:34 -050051 * \param pnlsr The NLSR object that contains the LSAs needed for adj. info.
52 *
53 * Calculates the list of next hops to every other router in the network.
54 */
akmhoque53353462014-04-22 08:43:45 -050055 void
56 calculate(Nlsr& pnlsr);
57
Nick G97e34942016-07-11 14:46:27 -050058 /*! \brief Adds a next hop to a routing table entry.
Nick Gordond0a7df32017-05-30 16:44:34 -050059 * \param destRouter The destination router whose RTE we want to modify.
60 * \param nh The next hop to add to the RTE.
61 */
akmhoque53353462014-04-22 08:43:45 -050062 void
akmhoque31d1d4b2014-05-05 22:08:14 -050063 addNextHop(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050064
Nick G97e34942016-07-11 14:46:27 -050065 /*! \brief Adds a next hop to a routing table entry in a dry run scenario.
Nick Gordond0a7df32017-05-30 16:44:34 -050066 * \param destRouter The destination router whose RTE we want to modify.
67 * \param nh The next hop to add to the router.
68 */
akmhoque53353462014-04-22 08:43:45 -050069 void
akmhoque31d1d4b2014-05-05 22:08:14 -050070 addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050071
akmhoqueb6450b12014-04-24 00:01:03 -050072 RoutingTableEntry*
akmhoque31d1d4b2014-05-05 22:08:14 -050073 findRoutingTableEntry(const ndn::Name& destRouter);
akmhoque53353462014-04-22 08:43:45 -050074
Nick Gordond0a7df32017-05-30 16:44:34 -050075 /*! \brief Schedules a calculation event in the event scheduler only
76 * if one isn't already scheduled.
77 * \param pnlsr The NLSR whose scheduling status is needed.
78 */
akmhoque53353462014-04-22 08:43:45 -050079 void
80 scheduleRoutingTableCalculation(Nlsr& pnlsr);
81
82 int
83 getNoNextHop()
84 {
85 return m_NO_NEXT_HOP;
86 }
87
Vince Lehman7b616582014-10-17 16:25:39 -050088 void
89 setRoutingCalcInterval(uint32_t interval)
90 {
91 m_routingCalcInterval = ndn::time::seconds(interval);
92 }
93
94 const ndn::time::seconds&
95 getRoutingCalcInterval() const
96 {
97 return m_routingCalcInterval;
98 }
99
akmhoque53353462014-04-22 08:43:45 -0500100private:
Nick G97e34942016-07-11 14:46:27 -0500101 /*! \brief Calculates a link-state routing table. */
akmhoque53353462014-04-22 08:43:45 -0500102 void
103 calculateLsRoutingTable(Nlsr& pnlsr);
104
Nick G97e34942016-07-11 14:46:27 -0500105 /*! \brief Calculates a HR routing table. */
akmhoque53353462014-04-22 08:43:45 -0500106 void
107 calculateHypRoutingTable(Nlsr& pnlsr);
108
Nick G97e34942016-07-11 14:46:27 -0500109 /*! \brief Calculates a dry-run HR routing table. */
akmhoque53353462014-04-22 08:43:45 -0500110 void
111 calculateHypDryRoutingTable(Nlsr& pnlsr);
112
113 void
114 clearRoutingTable();
115
116 void
117 clearDryRoutingTable();
118
akmhoque674b0b12014-05-20 14:33:28 -0500119 void
akmhoquedcee9362014-08-05 22:58:01 -0500120 writeLog(int hyperbolicState);
akmhoque674b0b12014-05-20 14:33:28 -0500121
Vince Lehman7c603292014-09-11 17:48:16 -0500122private:
123 ndn::Scheduler& m_scheduler;
124
akmhoque53353462014-04-22 08:43:45 -0500125 const int m_NO_NEXT_HOP;
126
127 std::list<RoutingTableEntry> m_rTable;
128 std::list<RoutingTableEntry> m_dryTable;
Vince Lehman7b616582014-10-17 16:25:39 -0500129
130 ndn::time::seconds m_routingCalcInterval;
akmhoque53353462014-04-22 08:43:45 -0500131};
132
Nick Gordonfad8e252016-08-11 14:21:38 -0500133} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500134
Nick Gordond0a7df32017-05-30 16:44:34 -0500135#endif // NLSR_ROUTING_TABLE_HPP